#include "pr2000_support.h"

#if defined(__HOST_LINUX_SYSTEM__)
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/miscdevice.h>
#include <linux/proc_fs.h>
#include <linux/kthread.h>
#include <linux/freezer.h>

#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/system.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/string.h>
#include <linux/list.h>
#include <asm/delay.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/poll.h>
#include <asm/bitops.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <linux/moduleparam.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>

#include <linux/i2c.h>

#elif defined(__HOST_MICOM_SYSTEM__)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if defined(STM32F10X_HD)
#include "stm32f10x.h"
#else
//#include "stm8s.h"
#endif

#include "i51_i2c_gpio.h"

//#include "uart.h"
//#include "delay.h"
//#include "user_func.h"

#endif // __HOST_LINUX_SYSTEM__

#include "pr2000.h"
#include "pr2000_table.h"
#include "pr2000_func.h"
#include "pr2000_ceqfunc.h"
#include "pr2000_user_config.h"

int PR2000_SetTableCommon(const int i2cFd, const uint8_t slvAddr);

int PR2000_SetTableIRQ(const int i2cFd, const uint8_t slvAddr)
{
	int result = -1;
	const _stPR2000_Table_Common *pTblIRQ = NULL;
	_stPR2000_Reg stReg;
	int regInx = 0;
	uint8_t u8RegData;

	Print("%02x-Set irq register\n", slvAddr);

	pTblIRQ = (const _stPR2000_Table_Common *)stPR2000_Table_IRQ;
	regInx = 0;
	stReg.reg = pTblIRQ[regInx].stReg.reg;
	while(stReg.reg != 0xFFFF)
	{
		u8RegData = pTblIRQ[regInx].u8Data;
		Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		regInx++;
		stReg.reg = pTblIRQ[regInx].stReg.reg;
	}

	/* get current novid status. and set novid level. */
	{/*{{{*/
		uint8_t novidStatus[3];
		uint8_t tryCnt = 0;
		uint8_t i = 0;

		do
		{
			for(i = 0; i < 3; i++)
			{
				stReg.reg = 0x0099;
				u8RegData = 0;
				if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
				{
					ErrorString("invalid page read\n");
					return(result);
				}
				novidStatus[i] = u8RegData&0x10;
				msleep(30);
			}
			tryCnt++;
		} while( (tryCnt < 4) && ((novidStatus[0] != novidStatus[1]) || (novidStatus[0] != novidStatus[2]) || (novidStatus[1] != novidStatus[2])) );
		Print("%02x-tryCnt:%d, currnet novid status:%d, invert level.\n", slvAddr COMMA tryCnt COMMA (u8RegData>>4)&1);

		stReg.reg = 0x0086; //LEVEL VFD/NOVID/GPIO8
		u8RegData = 0x20|((u8RegData&0x10)?0x10:0x00);
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
	}/*}}}*/

	return(result);
}

int PR2000_SetTableMipiParallel(const int i2cFd, const uint8_t slvAddr, const uint8_t vidOutMode, const uint8_t bStart, const enum _eCameraStandard cameraStandard, const enum _eVideoResolution videoResolution)
{
	int result = -1;
	const _stPR2000_Table_STD_HDResolution *pTblSTDHDResolution = NULL;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	const _stPR2000_Table_EXT_HDResolution *pTblEXTHDResolution = NULL;
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	const _stPR2000_Table_SDResolution *pTblSDResolution = NULL;
	_stPR2000_Reg stReg;
	int regInx = 0;
	uint8_t u8RegData;
	uint8_t u8RegMask;

	const _stPR2000_Table_Common *pTblMipi = NULL;
	const _stPR2000_Table_Common stPR2000_Table_StartMipi_4Lane[] = 
	{/*{{{*/
		/* page+reg, data */
		// MIPI Start Sequence
		{ {0x0040}, 0x00},           // dphy Start
		{ {0x004E}, 0x40},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 00h. 4lane
		{ {0x0040}, 0x40},           //enable mipi
		// 1usec dely
		{ {0x004E}, 0x60},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 20h : DLL_PD Toggle. 4lane
		// 1usec dely
		{ {0x004E}, 0x40},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 00h. 4lane
		// 1usec dely
		{ {0x0047}, 0xBA},       //mipi_en & Frame Mode. 4lane

		/* End */
		{  {0xFFFF}, 0xFF}, //end
	};/*}}}*/
	const _stPR2000_Table_Common stPR2000_Table_StartMipi_2Lane[] = 
	{/*{{{*/
		/* page+reg, data */
		// MIPI Start Sequence
		{ {0x0040}, 0x00},           // dphy Start
		{ {0x004E}, 0x4C},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 00h. 2lane
		{ {0x0040}, 0x40},           //enable mipi
		// 1usec dely
		{ {0x004E}, 0x6C},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 20h : DLL_PD Toggle. 2lane
		// 1usec dely
		{ {0x004E}, 0x4C},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 00h. 2lane
		// 1usec dely
		{ {0x0047}, 0x9A},       //mipi_en & Frame Mode. 2lane

		/* End */
		{  {0xFFFF}, 0xFF}, //end
	};/*}}}*/

	const _stPR2000_Table_Common stPR2000_Table_StopMipi_4Lane[] = 
	{/*{{{*/
		/* page+reg, data */
		{  {0x0047}, 0x3A},	 // 4lane
		{  {0x0040}, 0x00},
		{  {0x004E}, 0x7F},

		/* End */
		{  {0xFFFF}, 0xFF}, //end
	};/*}}}*/
	const _stPR2000_Table_Common stPR2000_Table_StopMipi_2Lane[] = 
	{/*{{{*/
		/* page+reg, data */
		{  {0x0047}, 0x1A},	 // 2lane
		{  {0x0040}, 0x00},
		{  {0x004E}, 0x7F},

		/* End */
		{  {0xFFFF}, 0xFF}, //end
	};/*}}}*/

	Print("%02x-[Mipi(2|4)|Parallel(0)](%d) %s Standard:%d, videoResolution:%d\n", slvAddr COMMA vidOutMode COMMA (bStart)?"Start":"Stop"  COMMA cameraStandard COMMA videoResolution);

	if(!bStart) //stop
	{/*{{{*/
		result = 0;
		if(vidOutMode != 0) //mipi mode
		{
			if(vidOutMode == 4)
			{
				pTblMipi = (const _stPR2000_Table_Common *)stPR2000_Table_StopMipi_4Lane;
			}
			else if(vidOutMode == 2)
			{
				pTblMipi = (const _stPR2000_Table_Common *)stPR2000_Table_StopMipi_2Lane;
			}
			else
			{
				ErrorString("Invalid vidOutMode\n");
				return(-1);
			}
			regInx = 0;
			stReg.reg = pTblMipi[regInx].stReg.reg;
			while(stReg.reg != 0xFFFF)
			{
				u8RegData = pTblMipi[regInx].u8Data;
				Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}

				if(stReg.reg == 0x0047)
				{
					/* waiting 1Frame Delay */
					msleep(40);
				}

				regInx++;
				stReg.reg = pTblMipi[regInx].stReg.reg;
			}
		}
		return(result);
	}/*}}}*/

	if(cameraStandard >= max_camera_standard)
	{
		Error("Invalid standard:%d\n", cameraStandard);
		return(result);
	}
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	if(videoResolution >= max_video_resolution)
	{
		Error("Invalid video resolution:%d\n", videoResolution);
		return(result);
	}
#else
	if(videoResolution > video_1920x1080p25)
	{
		Error("Invalid video resolution:%d\n", videoResolution);
		return(result);
	}
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	if(videoResolution > video_1920x1080p25)
	{/*{{{*/
		switch(cameraStandard)
		{
			case SD:
				{
					if(vidOutMode != 0)
					{
						pTblSDResolution = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SDMipiResol;
					}
					else
					{
						pTblSDResolution = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SDParallelResol;
					}
				}
				break;
			case PVI:
			case HDA:
			case CVI:
			case HDT_OLD:
			case HDT_NEW:
				{
					if(vidOutMode != 0)
					{
						pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution *)stPR2000_Table_EXT_HDMipiResol;
					}
					else
					{
						pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution *)stPR2000_Table_EXT_HDParallelResol;
					}
				}
				break;
			default:
				{
					Error("Invalid camera Standard(%d)\n", cameraStandard);
					return(result);
				}
		}
	}/*}}}*/
	else
	{/*{{{*/
		switch(cameraStandard)
		{/*{{{*/
			case SD:
				{
					if(vidOutMode != 0)
					{
						pTblSDResolution = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SDMipiResol;
					}
					else
					{
						pTblSDResolution = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SDParallelResol;
					}
				}
				break;
			case PVI:
			case HDA:
			case CVI:
			case HDT_OLD:
			case HDT_NEW:
				{
					if(vidOutMode != 0)
					{
						pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_HDMipiResol;
					}
					else
					{
						pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_HDParallelResol;
					}
				}
				break;
			default:
				{
					Error("Invalid camera Standard(%d)\n", cameraStandard);
					return(result);
				}
		}/*}}}*/
	}/*}}}*/
#else
	switch(cameraStandard)
	{/*{{{*/
		case SD:
			{
				if(vidOutMode != 0)
				{
					pTblSDResolution = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SDMipiResol;
				}
				else
				{
					pTblSDResolution = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SDParallelResol;
				}
			}
			break;
		case PVI:
		case HDA:
		case CVI:
		case HDT_OLD:
		case HDT_NEW:
			{
				if(vidOutMode != 0)
				{
					pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_HDMipiResol;
				}
				else
				{
					pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_HDParallelResol;
				}
			}
			break;
		default:
			{
				Error("Invalid camera Standard(%d)\n", cameraStandard);
				return(result);
			}
	}/*}}}*/
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

	if( (cameraStandard == SD) && (pTblSDResolution != NULL) )
	{
		regInx = 0;
		stReg.reg = pTblSDResolution[regInx].stReg.reg;
		while(stReg.reg != 0xFFFF)
		{
			u8RegData = pTblSDResolution[regInx].u8Data[videoResolution];
			Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
			if(stReg.reg == 0x00E0)
			{
				u8RegMask = 0x0F;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}
			else
			{
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}

			regInx++;
			stReg.reg = pTblSDResolution[regInx].stReg.reg;
		}
	}
	else
	{
		if( (pTblSTDHDResolution != NULL) )
		{/*{{{*/
			regInx = 0;
			stReg.reg = pTblSTDHDResolution[regInx].stReg.reg;
			while(stReg.reg != 0xFFFF)
			{
				u8RegData = pTblSTDHDResolution[regInx].u8Data[videoResolution-video_1280x720p60]; 
				Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
				if(stReg.reg == 0x00E0)
				{
					u8RegMask = 0x0F;
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}
				else
				{
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}

				regInx++;
				stReg.reg = pTblSTDHDResolution[regInx].stReg.reg;
			}
		}/*}}}*/
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
		if( (pTblEXTHDResolution != NULL) )
		{/*{{{*/
			regInx = 0;
			stReg.reg = pTblEXTHDResolution[regInx].stReg.reg;
			while(stReg.reg != 0xFFFF)
			{
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
				u8RegData = pTblEXTHDResolution[regInx].u8Data[videoResolution-video_1280x800p60]; 
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
				u8RegData = pTblEXTHDResolution[regInx].u8Data[videoResolution-video_1280x960p60]; 
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
				Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
				if(stReg.reg == 0x00E0)
				{
					u8RegMask = 0x0F;
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}
				else
				{
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}

				regInx++;
				stReg.reg = pTblEXTHDResolution[regInx].stReg.reg;
			}
		}/*}}}*/
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	}

	if(vidOutMode != 0) //0:parallel else mipi(2,4)
	{
		if(vidOutMode == 4)
		{
			pTblMipi = (const _stPR2000_Table_Common *)stPR2000_Table_StartMipi_4Lane;
		}
		else if(vidOutMode == 2)
		{
			pTblMipi = (const _stPR2000_Table_Common *)stPR2000_Table_StartMipi_2Lane;
		}
		else
		{
			ErrorString("Invalid vidOutMode\n");
			return(-1);
		}
		regInx = 0;
		stReg.reg = pTblMipi[regInx].stReg.reg;
		while(stReg.reg != 0xFFFF)
		{
			u8RegData = pTblMipi[regInx].u8Data;
			Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}

			regInx++;
			stReg.reg = pTblMipi[regInx].stReg.reg;
		}
	}

	return(result);

}

int PR2000_SetTableStdResol(const int i2cFd, const uint8_t slvAddr, const enum _eCameraStandard cameraStandard, const enum _eVideoResolution videoResolution)
{
	int result = -1;
	const _stPR2000_Table_STD_HDResolution *pTblSTDHDResolution = NULL;
	const _stPR2000_Table_ETC_STDResolution *pTblETCSTDResolution = NULL;
	const _stPR2000_Table_ETC_STDResolution *pTblETCSTDResolutionSync = NULL;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	const _stPR2000_Table_EXT_HDResolution *pTblEXTHDResolution = NULL;
	const _stPR2000_Table_ETC_EXTResolution *pTblETCEXTResolution = NULL;
	const _stPR2000_Table_ETC_EXTResolution *pTblETCEXTResolutionSync = NULL;
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	const _stPR2000_Table_SDResolution *pTblSDResolution = NULL;
	_stPR2000_Reg stReg;
	int regInx = 0;
	uint8_t u8RegData;
	uint8_t u8RegMask;
	int chipInx = 0;

	Print("%02x-Set VDEC Standard:%d, videoResolution:%d\n", slvAddr COMMA cameraStandard COMMA videoResolution);

	if(cameraStandard >= max_camera_standard)
	{
		Error("Invalid standard:%d\n", cameraStandard);
		return(result);
	}
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	if(videoResolution >= max_video_resolution)
	{
		Error("Invalid video resolution:%d\n", videoResolution);
		return(result);
	}
#else
	if(videoResolution > video_1920x1080p25)
	{
		Error("Invalid video resolution:%d\n", videoResolution);
		return(result);
	}
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

	/* get chip attribute */
	for(chipInx = 0; chipInx < MAX_PR2000_CHIPCNT; chipInx++)
	{
		if(PR2000_ATTR_CHIP[chipInx].i2cSlvAddr == slvAddr)
		{
			break;
		}
	}

#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	if(videoResolution > video_1920x1080p25)
	{
		pTblETCEXTResolution = (const _stPR2000_Table_ETC_EXTResolution *)stPR2000_Table_ETC_EXTResol;
		if(PR2000_ATTR_CHIP[chipInx].vidOutMode == 0) //parallel
		{
			pTblETCEXTResolutionSync = (const _stPR2000_Table_ETC_EXTResolution *)stPR2000_Table_ETC_EXTResol_SyncParallel;
		}
		else //mipi
		{
			pTblETCEXTResolutionSync = (const _stPR2000_Table_ETC_EXTResolution *)stPR2000_Table_ETC_EXTResol_SyncMipi;
		}
	}
	else
	{
		pTblETCSTDResolution = (const _stPR2000_Table_ETC_STDResolution *)stPR2000_Table_ETC_STDResol;
		if(PR2000_ATTR_CHIP[chipInx].vidOutMode == 0) //parallel
		{
			pTblETCSTDResolutionSync = (const _stPR2000_Table_ETC_STDResolution *)stPR2000_Table_ETC_STDResol_SyncParallel;
		}
		else //mipi
		{
			pTblETCSTDResolutionSync = (const _stPR2000_Table_ETC_STDResolution *)stPR2000_Table_ETC_STDResol_SyncMipi;
		}
	}
#else
	pTblETCSTDResolution = (const _stPR2000_Table_ETC_STDResolution *)stPR2000_Table_ETC_STDResol;
	if(PR2000_ATTR_CHIP[chipInx].vidOutMode == 0) //parallel
	{
		pTblETCSTDResolutionSync = (const _stPR2000_Table_ETC_STDResolution *)stPR2000_Table_ETC_STDResol_SyncParallel;
	}
	else //mipi
	{
		pTblETCSTDResolutionSync = (const _stPR2000_Table_ETC_STDResolution *)stPR2000_Table_ETC_STDResol_SyncMipi;
	}
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

	// Write etc setting for standard
	if(videoResolution <= video_1920x1080p25)
	{/*{{{*/
		regInx = 0;
		stReg.reg = pTblETCSTDResolution[regInx].stReg.reg;
		Print("%02x-Write etc setting for standard\n", slvAddr);
		while(stReg.reg != 0xFFFF)
		{
			u8RegData = pTblETCSTDResolution[regInx].u8Data[videoResolution];
			Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}

			regInx++;
			stReg.reg = pTblETCSTDResolution[regInx].stReg.reg;
		}

		regInx = 0;
		stReg.reg = pTblETCSTDResolutionSync[regInx].stReg.reg;
		Dbg("%02x-Write etc sync setting for standard\n", slvAddr);
		while(stReg.reg != 0xFFFF)
		{
			u8RegData = pTblETCSTDResolutionSync[regInx].u8Data[videoResolution];
			Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}

			regInx++;
			stReg.reg = pTblETCSTDResolutionSync[regInx].stReg.reg;
		}
	}/*}}}*/
	else
	{/*{{{*/
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
		regInx = 0;
		stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
		Print("%02x-Write etc setting for extend\n", slvAddr);
		while(stReg.reg != 0xFFFF)
		{
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
			u8RegData = pTblETCEXTResolution[regInx].u8Data[videoResolution-video_1280x800p60]; 
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
			u8RegData = pTblETCEXTResolution[regInx].u8Data[videoResolution-video_1280x960p60]; 
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
			Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}

			regInx++;
			stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
		}

		regInx = 0;
		stReg.reg = pTblETCEXTResolutionSync[regInx].stReg.reg;
		Dbg("%02x-Write etc sync setting for extend\n", slvAddr);
		while(stReg.reg != 0xFFFF)
		{
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
			u8RegData = pTblETCEXTResolutionSync[regInx].u8Data[videoResolution-video_1280x800p60]; 
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
			u8RegData = pTblETCEXTResolutionSync[regInx].u8Data[videoResolution-video_1280x960p60]; 
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
			Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}

			regInx++;
			stReg.reg = pTblETCEXTResolutionSync[regInx].stReg.reg;
		}

#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	}/*}}}*/


#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	if(videoResolution > video_1920x1080p25)
	{/*{{{*/
		switch(cameraStandard)
		{
			case SD:
				{
					pTblSDResolution = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SDResol;
				}
				break;
#if defined(SUPPORT_STD_PVI)
			case PVI:
				{
					pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution *)stPR2000_Table_EXT_PVIResol;
				}
				break;
#endif //defined(SUPPORT_STD_PVI)
#if defined(SUPPORT_STD_HDA)
			case HDA:
				{
					pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution *)stPR2000_Table_EXT_HDAResol;
				}
				break;
#endif //defined(SUPPORT_STD_HDA)
#if defined(SUPPORT_STD_CVI)
			case CVI:
				{
					pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution *)stPR2000_Table_EXT_CVIResol;
				}
				break;
#endif //defined(SUPPORT_STD_CVI)
#if defined(SUPPORT_STD_HDT)
			case HDT_OLD:
				{
					pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution *)stPR2000_Table_EXT_HDT_OLDResol;
				}
				break;
			case HDT_NEW:
				{
					pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution *)stPR2000_Table_EXT_HDT_NEWResol;
				}
				break;
#endif //defined(SUPPORT_STD_HDT)
			default:
				{
					Error("Invalid camera Standard(%d)\n", cameraStandard);
					return(result);
				}
		}
	}/*}}}*/
	else
	{/*{{{*/
		switch(cameraStandard)
		{
			case SD:
				{
					pTblSDResolution = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SDResol;
				}
				break;
#if defined(SUPPORT_STD_PVI)
			case PVI:
				{
					pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_PVIResol;
				}
				break;
#endif //defined(SUPPORT_STD_PVI)
#if defined(SUPPORT_STD_HDA)
			case HDA:
				{
					pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_HDAResol;
				}
				break;
#endif //defined(SUPPORT_STD_HDA)
#if defined(SUPPORT_STD_CVI)
			case CVI:
				{
					pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_CVIResol;
				}
				break;
#endif //defined(SUPPORT_STD_CVI)
#if defined(SUPPORT_STD_HDT)
			case HDT_OLD:
				{
					pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_HDT_OLDResol;
				}
				break;
			case HDT_NEW:
				{
					pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_HDT_NEWResol;
				}
				break;
#endif //defined(SUPPORT_STD_HDT)
			default:
				{
					Error("Invalid camera Standard(%d)\n", cameraStandard);
					return(result);
				}
		}
	}/*}}}*/
#else
	switch(cameraStandard)
	{/*{{{*/
		case SD:
			{
				pTblSDResolution = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SDResol;
			}
			break;
#if defined(SUPPORT_STD_PVI)
		case PVI:
			{
				pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_PVIResol;
			}
			break;
#endif //defined(SUPPORT_STD_PVI)
#if defined(SUPPORT_STD_HDA)
		case HDA:
			{
				pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_HDAResol;
			}
			break;
#endif //defined(SUPPORT_STD_HDA)
#if defined(SUPPORT_STD_CVI)
		case CVI:
			{
				pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_CVIResol;
			}
			break;
#endif //defined(SUPPORT_STD_CVI)
#if defined(SUPPORT_STD_HDT)
		case HDT_OLD:
			{
				pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_HDT_OLDResol;
			}
			break;
		case HDT_NEW:
			{
				pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STD_HDT_NEWResol;
			}
			break;
#endif //defined(SUPPORT_STD_HDT)
		default:
			{
				Error("Invalid camera Standard(%d)\n", cameraStandard);
				return(result);
			}
	}/*}}}*/
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

	if( (cameraStandard == SD) && (pTblSDResolution != NULL) )
	{
		regInx = 0;
		stReg.reg = pTblSDResolution[regInx].stReg.reg;
		while(stReg.reg != 0xFFFF)
		{
			u8RegData = pTblSDResolution[regInx].u8Data[videoResolution];
			Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
			if(stReg.reg == 0x00E0)
			{
				u8RegMask = 0x0F;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}
			else
			{
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}

			regInx++;
			stReg.reg = pTblSDResolution[regInx].stReg.reg;
		}
	}
	else
	{
		if( (pTblSTDHDResolution != NULL) )
		{/*{{{*/
			regInx = 0;
			stReg.reg = pTblSTDHDResolution[regInx].stReg.reg;
			while(stReg.reg != 0xFFFF)
			{
				u8RegData = pTblSTDHDResolution[regInx].u8Data[videoResolution-video_1280x720p60]; 
				Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
				if(stReg.reg == 0x00E0)
				{
					u8RegMask = 0x0F;
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}
				else
				{
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}

				regInx++;
				stReg.reg = pTblSTDHDResolution[regInx].stReg.reg;
			}
		}/*}}}*/
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
		if( (pTblEXTHDResolution != NULL) )
		{/*{{{*/
			regInx = 0;
			stReg.reg = pTblEXTHDResolution[regInx].stReg.reg;
			while(stReg.reg != 0xFFFF)
			{
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
				u8RegData = pTblEXTHDResolution[regInx].u8Data[videoResolution-video_1280x800p60]; 
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
				u8RegData = pTblEXTHDResolution[regInx].u8Data[videoResolution-video_1280x960p60]; 
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
				Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
				if(stReg.reg == 0x00E0)
				{
					u8RegMask = 0x0F;
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}
				else
				{
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}

				regInx++;
				stReg.reg = pTblEXTHDResolution[regInx].stReg.reg;
			}
		}/*}}}*/
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	}

	PR2000_SetTableMipiParallel(i2cFd, slvAddr, PR2000_ATTR_CHIP[chipInx].vidOutMode, START, cameraStandard, videoResolution);

	/* Apply Set register */
	{/*{{{*/

		stReg.reg = 0x0154;
		u8RegData = 0x0E;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		stReg.reg = 0x0154;
		u8RegData = 0x0F;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
	}/*}}}*/

	/* should wait 400msec. for stable detection of std&resol. */
	msleep(400);

	return(result);

}

int PR2000_Initialize(const int i2cFd, const uint8_t slvAddr)
{
	int result = -1;

	enum _eCameraStandard cameraStandard;
	enum _eCameraResolution cameraResolution;
	enum _eVideoResolution videoResolution;

	int chipInx = 0;
	/* get chip number. */
	for(chipInx = 0; chipInx < gFindPr2000SlvAddrCnt; chipInx++)
	{
		if(PR2000_ATTR_CHIP[chipInx].i2cSlvAddr == slvAddr)
		{
			break;
		}
	}

#if defined(__HOST_MICOM_SYSTEM__)
	if(gpDrvHost[chipInx] == NULL)
	{
		memset(&gDrvHost[chipInx], 0, sizeof(_drvHost));
		gpDrvHost[chipInx] = (_drvHost *)&gDrvHost[chipInx];

		gpDrvHost[chipInx]->stPrRxMode.standard = (enum _eCameraStandard)DEFAULT_CAMERA_STANDARD;
		gpDrvHost[chipInx]->stPrRxMode.cameraResolution = (enum _eCameraResolution)DEFAULT_CAMERA_RESOLUTION;
		gpDrvHost[chipInx]->stPrRxMode.vidOutResolution = (enum _eVideoResolution)stDefaultCameraVideoRelation[DEFAULT_CAMERA_RESOLUTION].eVideoResolution;
	}
#endif //defined(__HOST_MICOM_SYSTEM__)

	if( (gpDrvHost[chipInx]->stPrRxMode.cameraResolution == camera_ntsc) || (gpDrvHost[chipInx]->stPrRxMode.cameraResolution == camera_pal) )
	{
		gpDrvHost[chipInx]->stPrRxMode.standard = SD;
	}

	cameraStandard = gpDrvHost[chipInx]->stPrRxMode.standard;
	cameraResolution = gpDrvHost[chipInx]->stPrRxMode.cameraResolution;
	videoResolution = gpDrvHost[chipInx]->stPrRxMode.vidOutResolution;

	Print("### PR2000 Driver Version : v%s ### chipinx:%d\n", _VER_PR2000 COMMA chipInx);
	Print("%02x-Init Camera:%d(%s), cameraResolution:%d(%s), videoResolution:%d(%s)\n", slvAddr COMMA cameraStandard COMMA _strCameraStandard[cameraStandard] COMMA cameraResolution COMMA _strCameraResolution[cameraResolution] COMMA videoResolution COMMA _strVideoResolution[videoResolution]);
	if( (result = PR2000_SetTableCommon(i2cFd, slvAddr) ) < 0)
	{
		ErrorString("SetTableCommon\n");
		return(result);
	}
	if( (result = PR2000_SetTableStdResol(i2cFd, slvAddr, cameraStandard, videoResolution)) < 0)
	{
		ErrorString("SetTableStResol\n");
		return(result);
	}

	if( (result = PR2000_SetAttrChip(i2cFd, slvAddr, &PR2000_ATTR_CHIP[chipInx])) < 0)
	{
		ErrorString("SetAttrChip\n");
		return(result);
	}
	if( (result = PR2000_SetTableIRQ(i2cFd, slvAddr)) < 0)
	{
		ErrorString("SetTableIRQ\n");
		return(result);
	}
#ifdef SUPPORT_UTC
	if( (result = PR2000_UTC_SetTable(i2cFd, slvAddr, cameraStandard, cameraResolution)) < 0)
	{
		ErrorString("UTC_SetTable\n");
		return(result);
	}
#endif // SUPPORT_UTC
#ifdef SUPPORT_OSG
	if( (result = PR2000_OSG_SetTable(i2cFd, slvAddr, cameraStandard, videoResolution)) < 0)
	{
		ErrorString("OSG_SetTable\n");
		return(result);
	}
#endif // SUPPORT_OSG
	if( (result = PR2000_SetAttrGpioPin(i2cFd, slvAddr, &PR2000_ATTR_GPIOPIN[chipInx])) < 0)
	{
		ErrorString("SetAttrGpioPin\n");
		return(result);
	}
#ifdef SUPPORT_FPGA
	if( (result = PR2000_FPGA_SetTable(i2cFd, slvAddr)) < 0)
	{
		ErrorString("FPGA_SetTable\n");
		return(result);
	}
#endif // SUPPORT_FPGA
#ifdef SUPPORT_CPLD
	if(chipInx == 0)
	{
		if( (result = PR2000_CPLD_SetTable(PR2000_ATTR_CHIP[chipInx].vidOutMode, PR2000_ATTR_CHIP[chipInx].datarate)) < 0)
		{
			ErrorString("CPLD_SetTable\n");
			return(result);
		}
	}
#endif // SUPPORT_CPLD
	return(result);
}

int PR2000_Isr(const int i2cFd, const uint8_t slvAddr, void *pArg)
{
	int result = -1;
	_drvHost *pHost = (_drvHost *)pArg;
	_stPR2000_Isr *pstIsr = (_stPR2000_Isr *)&pHost->stPR2000_Isr;
	_stPR2000_Reg stReg;
	uint8_t u8RegMask;
	uint8_t u8RegData = 0;
	int i;
	int regInx = 0;
//	enum _eVideoResolution videoResolution;
	_stPR2000_VidStatusReg curStVidStatusReg;

#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	const _stPR2000_Table_ETC_EXTResolution *pTblETCEXTResolution = NULL;
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

	/* get irq clr & status */
	{/*{{{*/
		PR2000_SetPage(i2cFd, slvAddr, 0);
		stReg.reg = 0x0094;
		if( (result = PR2000_Read(i2cFd, slvAddr, stReg.b.addr, &u8RegData)) < 0)
		{
			ErrorString("can't read\n");
			return(result);
		}
		pstIsr->stIrqClr.reg[0] = u8RegData;
		stReg.reg = 0x0095;
		if( (result = PR2000_Read(i2cFd, slvAddr, stReg.b.addr, &u8RegData)) < 0)
		{
			ErrorString("can't read\n");
			return(result);
		}
		pstIsr->stIrqClr.reg[1] = u8RegData;
		stReg.reg = 0x0096;
		if( (result = PR2000_Read(i2cFd, slvAddr, stReg.b.addr, &u8RegData)) < 0)
		{
			ErrorString("can't read\n");
			return(result);
		}
		pstIsr->stIrqClr.reg[2] = u8RegData;

		PR2000_SetPage(i2cFd, slvAddr, 0);
		stReg.reg = 0x0098;
		if( (result = PR2000_Read(i2cFd, slvAddr, stReg.b.addr, &u8RegData)) < 0)
		{
			ErrorString("can't read\n");
			return(result);
		}
		pstIsr->stIrqStatus.reg[0] = u8RegData;
		stReg.reg = 0x0099;
		if( (result = PR2000_Read(i2cFd, slvAddr, stReg.b.addr, &u8RegData)) < 0)
		{
			ErrorString("can't read\n");
			return(result);
		}
		pstIsr->stIrqStatus.reg[1] = u8RegData;
		stReg.reg = 0x009A;
		if( (result = PR2000_Read(i2cFd, slvAddr, stReg.b.addr, &u8RegData)) < 0)
		{
			ErrorString("can't read\n");
			return(result);
		}
		pstIsr->stIrqStatus.reg[2] = u8RegData;

	}/*}}}*/
	Dbg("%02x-Irq:0x%02x/0x%02x/0x%02x\n", slvAddr COMMA pstIsr->stIrqClr.reg[2] COMMA pstIsr->stIrqClr.reg[1] COMMA pstIsr->stIrqClr.reg[0]);

	if(pstIsr->stIrqClr.b.novid)
	{/*{{{*/
		Print("%02x-NOVID:%d\n", slvAddr COMMA pstIsr->stIrqStatus.b.novid);
		if(pstIsr->stIrqStatus.b.novid) //Video->Novideo
		{
			/* stop VFD irq */
			{/*{{{*/
				stReg.reg = 0x0091;
				u8RegMask = 0x20;
				u8RegData = 0x00;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
			/* Init CEQ gain register. */
			{/*{{{*/
				stReg.reg = 0x0011;
				u8RegData = 0x00;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0013;
				u8RegData = 0x00;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/

			/* initialize argument */
			memset(&pstIsr->stJobProc, 0, sizeof(_stJobProc));

			/* set next camera plug in level interrupt */
			stReg.reg = 0x0086;
			u8RegMask = 0x10;
			u8RegData = (uint8_t)~(pstIsr->stIrqStatus.b.novid<<4);
			if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}

			/* If Mipi, Stop */
			{
				int chipInx = 0;
				/* get chip attribute */
				for(chipInx = 0; chipInx < MAX_PR2000_CHIPCNT; chipInx++)
				{
					if(PR2000_ATTR_CHIP[chipInx].i2cSlvAddr == slvAddr)
					{
						break;
					}
				}

				PR2000_SetTableMipiParallel(i2cFd, slvAddr, PR2000_ATTR_CHIP[chipInx].vidOutMode, STOP, max_camera_standard, max_video_resolution);
			}

			Print("%02x-Vide->Novideo interrupt\n", slvAddr);
			_SET_BIT(IRQ_NOVID, &pstIsr->stUserPoll.bitIrq);
			_SET_BIT(IRQ_NOVID, &pstIsr->stUserPoll.bitIrqStatus);
		}
		else //Novideo->Video
		{
			if(!_TEST_BIT(JOB_START_CAMERA_IN, &pstIsr->stJobProc.bitJobProcess))
			{
				PR2000_ReadVidStatusReg(i2cFd, slvAddr, &curStVidStatusReg);
				Dbg("%02x,%02x,%02x\n", curStVidStatusReg.reg[0] COMMA curStVidStatusReg.reg[1] COMMA curStVidStatusReg.reg[2]);
				if( (curStVidStatusReg.b.lock_gain) && (curStVidStatusReg.b.lock_clamp) && (curStVidStatusReg.b.lock_hperiod) )
				{
					pstIsr->stJobProc.camPlugInCheckCnt++;
				}
				else
				{
					/* wait stable status */
					pstIsr->stJobProc.camPlugInCheckCnt = 0;
					pstIsr->stJobProc.cntJobTry++;
				}
				Print("%02x-camPlugInCheckCnt:%d, tryCnt:%d\n", slvAddr COMMA pstIsr->stJobProc.camPlugInCheckCnt COMMA pstIsr->stJobProc.cntJobTry);

				/* stable camera plugin(camPlugInCheckCnt>=2) or unstable(cntJobTry>=4). if unstable, forcely set detect CVI. */
				if( (pstIsr->stJobProc.camPlugInCheckCnt >= 3) || (pstIsr->stJobProc.cntJobTry >= 4) )
				{/*{{{*/
					Print("%02x-Novideo->Video interrupt\n", slvAddr);
					_SET_BIT(IRQ_NOVID, &pstIsr->stUserPoll.bitIrq);
					_CLEAR_BIT(IRQ_NOVID, &pstIsr->stUserPoll.bitIrqStatus);

					/* Write pre setting for 800p/900p. For valid operating 800p/900p */
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
					if( curStVidStatusReg.b.det_ifmt_res == DET_HD960p)
					{/*{{{*/
						pTblETCEXTResolution = (const _stPR2000_Table_ETC_EXTResolution *)stPR2000_Table_ETC_EXTResol;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
						Print("%02x-Write pre setting for 800p(ref:%d)\n", slvAddr COMMA curStVidStatusReg.b.det_ifmt_ref);
						switch( curStVidStatusReg.b.det_ifmt_ref )
						{/*{{{*/
							case DET_25Hz: videoResolution = video_1280x800p25; break;
							case DET_30Hz: videoResolution = video_1280x800p30; break;
							case DET_50Hz: videoResolution = video_1280x800p50; break;
							case DET_60Hz: videoResolution = video_1280x800p60; break;
							default: videoResolution = video_1280x800p25; break;
						}/*}}}*/
						regInx = 0;
						stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
						while(stReg.reg != 0xFFFF)
						{
							u8RegData = pTblETCEXTResolution[regInx].u8Data[videoResolution-video_1280x800p60]; 
							Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

							if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
							{
								ErrorString("invalid page write\n");
								return(result);
							}

							regInx++;
							stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
						}
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
						Print("%02x-Write pre setting for 960p(ref:%d)\n", slvAddr COMMA curStVidStatusReg.b.det_ifmt_ref);
						switch( curStVidStatusReg.b.det_ifmt_ref )
						{/*{{{*/
							case DET_25Hz: videoResolution = video_1280x960p25; break;
							case DET_30Hz: videoResolution = video_1280x960p30; break;
							case DET_50Hz: videoResolution = video_1280x960p50; break;
							case DET_60Hz: videoResolution = video_1280x960p60; break;
							default: videoResolution = video_1280x960p25; break;
						}/*}}}*/

						regInx = 0;
						stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
						while(stReg.reg != 0xFFFF)
						{
							u8RegData = pTblETCEXTResolution[regInx].u8Data[videoResolution-video_1280x960p60]; 
							Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

							if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
							{
								ErrorString("invalid page write\n");
								return(result);
							}

							regInx++;
							stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
						}
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
					}/*}}}*/
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

					/* set next novideo level interrupt */
					stReg.reg = 0x0086;
					u8RegMask = 0x10;
					u8RegData = (uint8_t)~(pstIsr->stIrqStatus.b.novid<<4);
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}

					/* save cur video status registers */
					memcpy(&pstIsr->stJobProc.stStartVidStatusReg, &curStVidStatusReg, sizeof(_stPR2000_VidStatusReg));
					memcpy(&pstIsr->stJobProc.stVidStatusReg, &curStVidStatusReg, sizeof(_stPR2000_VidStatusReg));
					if( (pstIsr->stJobProc.cntJobTry >= 4) )
					{
						Print("%02x-Forcely Set abnormal [CVI 1080p25]\n", slvAddr);
						pstIsr->stJobProc.stVidStatusReg.b.det_ifmt_std = DET_CVI;
						pstIsr->stJobProc.stVidStatusReg.b.det_ifmt_ref = DET_25Hz;
						pstIsr->stJobProc.stVidStatusReg.b.det_ifmt_res = DET_HD1080p;
					}
					pstIsr->stJobProc.cntJobTry = 0;

					/* set start camera in flag */
					_SET_BIT(JOB_START_CAMERA_IN, &pstIsr->stJobProc.bitJobProcess);
					pstIsr->stJobProc.numJobStep = 1;
					/* do timer1 process next isr. */
					if(pstIsr->stIrqClr.b.timer1) 
					{
						/* if current timer1 interrupt set, wait next timer1 interrupt. */
						pstIsr->stJobProc.cntWait300MsecTime = 1;
					}
					else
					{
						/* if not current timer1 interrupt set, dont' wait next timer1 interrupt. */
						pstIsr->stJobProc.cntWait300MsecTime = 0;
					}

					/* next processing in timer1 isr. *///periodic job 300msec
				}/*}}}*/
			}
		}
	}/*}}}*/
	if(pstIsr->stIrqClr.b.vfd)
	{/*{{{*/
		Print("%02x-VFD:%d(novideo:%d)\n", slvAddr COMMA pstIsr->stIrqStatus.b.vfd COMMA pstIsr->stIrqStatus.b.novid);

		if(pstIsr->stIrqStatus.b.novid == 0)
		{
			pstIsr->stIrqClr.b.vfd = 0; //Don't clear irq

			/* If Mipi, Stop */
			{
				int chipInx = 0;
				/* get chip attribute */
				for(chipInx = 0; chipInx < MAX_PR2000_CHIPCNT; chipInx++)
				{
					if(PR2000_ATTR_CHIP[chipInx].i2cSlvAddr == slvAddr)
					{
						break;
					}
				}

				PR2000_SetTableMipiParallel(i2cFd, slvAddr, PR2000_ATTR_CHIP[chipInx].vidOutMode, STOP, max_camera_standard, max_video_resolution);
			}


			if(!_TEST_BIT(JOB_START_VFD_CAMERA, &pstIsr->stJobProc.bitJobProcess) && !_TEST_BIT(JOB_DONE_VFD_CAMERA, &pstIsr->stJobProc.bitJobProcess))
			{
				/* initialize argument */
				memset(&pstIsr->stJobProc, 0, sizeof(_stJobProc));
				Print("%02x-Start VFD interrupt\n", slvAddr);
				_SET_BIT(IRQ_VFD, &pstIsr->stUserPoll.bitIrq);
				_SET_BIT(IRQ_VFD, &pstIsr->stUserPoll.bitIrqStatus);

				_SET_BIT(JOB_START_VFD_CAMERA, &pstIsr->stJobProc.bitJobProcess);

			}
			else
			{
				PR2000_ReadVidStatusReg(i2cFd, slvAddr, &curStVidStatusReg);
				if( (curStVidStatusReg.b.lock_gain) && (curStVidStatusReg.b.lock_clamp) && (curStVidStatusReg.b.lock_hperiod) )
				{
					pstIsr->stJobProc.camPlugInCheckCnt++;
				}
				else
				{
					/* wait stable status */
					pstIsr->stJobProc.camPlugInCheckCnt = 0;
					pstIsr->stJobProc.cntJobTry++;
				}
				Print("%02x-VFD camPlugInCheckCnt:%d, tryCnt:%d\n", slvAddr COMMA pstIsr->stJobProc.camPlugInCheckCnt COMMA pstIsr->stJobProc.cntJobTry);

				if( (pstIsr->stJobProc.camPlugInCheckCnt >= 2) || (pstIsr->stJobProc.cntJobTry >= 4) )
				{/*{{{*/

					pstIsr->stIrqClr.b.vfd = 1; //Clear irq
					_SET_BIT(IRQ_VFD, &pstIsr->stUserPoll.bitIrq);
					_CLEAR_BIT(IRQ_VFD, &pstIsr->stUserPoll.bitIrqStatus);

					/* Write pre setting for 800p/900p. For valid operating 800p/900p */
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
					if( curStVidStatusReg.b.det_ifmt_res == DET_HD960p)
					{/*{{{*/
						pTblETCEXTResolution = (const _stPR2000_Table_ETC_EXTResolution *)stPR2000_Table_ETC_EXTResol;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
						Print("%02x-Write pre setting for 800p(ref:%d)\n", slvAddr COMMA curStVidStatusReg.b.det_ifmt_ref);
						switch( curStVidStatusReg.b.det_ifmt_ref )
						{/*{{{*/
							case DET_25Hz: videoResolution = video_1280x800p25; break;
							case DET_30Hz: videoResolution = video_1280x800p30; break;
							case DET_50Hz: videoResolution = video_1280x800p50; break;
							case DET_60Hz: videoResolution = video_1280x800p60; break;
							default: videoResolution = video_1280x800p25; break;
						}/*}}}*/
						regInx = 0;
						stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
						while(stReg.reg != 0xFFFF)
						{
							u8RegData = pTblETCEXTResolution[regInx].u8Data[videoResolution-video_1280x800p60]; 
							Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

							if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
							{
								ErrorString("invalid page write\n");
								return(result);
							}

							regInx++;
							stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
						}
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
						Print("%02x-Write pre setting for 960p(ref:%d)\n", slvAddr COMMA curStVidStatusReg.b.det_ifmt_ref);
						switch( curStVidStatusReg.b.det_ifmt_ref )
						{/*{{{*/
							case DET_25Hz: videoResolution = video_1280x960p25; break;
							case DET_30Hz: videoResolution = video_1280x960p30; break;
							case DET_50Hz: videoResolution = video_1280x960p50; break;
							case DET_60Hz: videoResolution = video_1280x960p60; break;
							default: videoResolution = video_1280x960p25; break;
						}/*}}}*/

						regInx = 0;
						stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
						while(stReg.reg != 0xFFFF)
						{
							u8RegData = pTblETCEXTResolution[regInx].u8Data[videoResolution-video_1280x960p60]; 
							Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

							if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
							{
								ErrorString("invalid page write\n");
								return(result);
							}

							regInx++;
							stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
						}
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
					}/*}}}*/
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

					/* stop VFD irq */
					{/*{{{*/
						stReg.reg = 0x0091;
						u8RegMask = 0x20;
						u8RegData = 0x00;
						if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
						{
							ErrorString("invalid page write\n");
							return(result);
						}
					}/*}}}*/
					/* initialize argument */
					memset(&pstIsr->stJobProc, 0, sizeof(_stJobProc));

					/* save cur video status registers */
					memcpy(&pstIsr->stJobProc.stStartVidStatusReg, &curStVidStatusReg, sizeof(_stPR2000_VidStatusReg));
					memcpy(&pstIsr->stJobProc.stVidStatusReg, &curStVidStatusReg, sizeof(_stPR2000_VidStatusReg));
					if( (pstIsr->stJobProc.cntJobTry >= 4) )
					{
						Print("%02x-Forcely Set abnormal [CVI 1080p25]\n", slvAddr);
						pstIsr->stJobProc.stVidStatusReg.b.det_ifmt_std = DET_CVI;
						pstIsr->stJobProc.stVidStatusReg.b.det_ifmt_ref = DET_25Hz;
						pstIsr->stJobProc.stVidStatusReg.b.det_ifmt_res = DET_HD1080p;
					}
					pstIsr->stJobProc.cntJobTry = 0;

					/* set start camera in flag */
					_SET_BIT(JOB_START_CAMERA_IN, &pstIsr->stJobProc.bitJobProcess);
					_SET_BIT(JOB_DONE_VFD_CAMERA, &pstIsr->stJobProc.bitJobProcess);
					pstIsr->stJobProc.numJobStep = 1;
					/* do timer1 process next isr */
					if(pstIsr->stIrqClr.b.timer1) 
					{
						pstIsr->stJobProc.cntWait300MsecTime = 1;
					}
					else
					{
						pstIsr->stJobProc.cntWait300MsecTime = 0;
					}
				}/*}}}*/
			}
		}
	}/*}}}*/
	if(pstIsr->stIrqClr.b.spi)
	{/*{{{*/
		Dbg("SPI:%d\n", pstIsr->stIrqStatus.b.spi);
		_SET_BIT(IRQ_SPI, &pstIsr->stUserPoll.bitIrq);
	}/*}}}*/
#ifdef SUPPORT_UTC
	if(pstIsr->stIrqClr.reg[0] != 0) //ptz
	{
		Print("%02x-PTZ:0x%02x\n", slvAddr COMMA pstIsr->stIrqClr.reg[0]);
		_SET_BIT(IRQ_UTC, &pstIsr->stUserPoll.bitIrq);
		if(pstIsr->stIrqClr.b.ptz0) //tx done
		{/*{{{*/
			DbgString("Ptz0. Tx Done.\n");
			_SET_BIT(IRQ_UTC_TX, &pstIsr->stUserPoll.bitIrq);
		}/*}}}*/
		if(pstIsr->stIrqClr.b.ptz1) //tx fifo empty
		{/*{{{*/
			DbgString("Ptz1. Tx fifo empty.\n");
			/* reset tx fifo */
			{/*{{{*/
				stReg.reg = 0x0220;
				u8RegMask = 0x80;
				u8RegData = 0x00;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0210;
				u8RegMask = 0x87;
				u8RegData = 0x80;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0220;
				u8RegMask = 0x80;
				u8RegData = 0x80;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
		}/*}}}*/
		if(pstIsr->stIrqClr.b.ptz2) //tx fifo overflow
		{/*{{{*/
			DbgString("Ptz2. Tx fifo overflow.\n");
			/* reset tx fifo */
			{/*{{{*/
				stReg.reg = 0x0220;
				u8RegMask = 0x80;
				u8RegData = 0x00;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0210;
				u8RegMask = 0x87;
				u8RegData = 0x80;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0220;
				u8RegMask = 0x80;
				u8RegData = 0x80;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
		}/*}}}*/
		if(pstIsr->stIrqClr.b.ptz3) //rx fifo received data
		{/*{{{*/
			uint8_t u8RxFifoSize = 0;
			uint8_t pu8TempRecvBuffer[MAX_PR2000_UTC_BUF_SIZE] = {0, };

			DbgString("Ptz3.\n");
			/* get size of rx fifo */
			stReg.reg = 0x0215;
			if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RxFifoSize)) < 0)
			{
				ErrorString("invalid page read\n");
				return(result);
			}
			Dbg("UTC Rx size:%d\n", u8RxFifoSize);
			if(u8RxFifoSize > MAX_PR2000_UTC_BUF_SIZE)
			{
				/* reset rx fifo */
				{/*{{{*/
					stReg.reg = 0x0200;
					u8RegMask = 0x80;
					u8RegData = 0x00;
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					stReg.reg = 0x0214;
					u8RegMask = 0x87;
					u8RegData = 0x83;
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					stReg.reg = 0x0200;
					u8RegMask = 0x80;
					u8RegData = 0x80;
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}/*}}}*/
			}
			else
			{
				if(u8RxFifoSize)
				{
					/* ready read fifo */
					stReg.reg = 0x0214;
					u8RegMask = 0x17; 
					u8RegData = 0x13; // 1'st set pre-loaddata bit before read fifo.
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					for(i = 0; i < u8RxFifoSize; i++)
					{
						stReg.reg = 0x0216;
						if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &pu8TempRecvBuffer[i])) < 0)
						{
							ErrorString("invalid page read\n");
							return(result);
						}
					}
					DbgString("UTC Recv:");
					for(i = 0; i < u8RxFifoSize; i++)
					{
						PRINTF(" 0x%02x,", pu8TempRecvBuffer[i]);
						pHost->stUTCRecvCmd.utcCmd[i] = pu8TempRecvBuffer[i];
					}
					PRINTF("\r\n");
					pHost->stUTCRecvCmd.utcCmdLength = u8RxFifoSize;

					_SET_BIT(IRQ_UTC_RX, &pstIsr->stUserPoll.bitIrq);
				}
				else
				{
					ErrorString("invalid rxfifosize\n");
				}
			}

		}/*}}}*/
		if(pstIsr->stIrqClr.b.ptz4) //rx fifo empty
		{/*{{{*/
			DbgString("Ptz4. Rx fifo empty.\n");
			/* reset rx fifo */
			{/*{{{*/
				stReg.reg = 0x0200;
				u8RegMask = 0x80;
				u8RegData = 0x00;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0214;
				u8RegMask = 0x87;
				u8RegData = 0x83;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0200;
				u8RegMask = 0x80;
				u8RegData = 0x80;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
		}/*}}}*/
		if(pstIsr->stIrqClr.b.ptz5) //rx fifo overflow
		{/*{{{*/
			DbgString("Ptz5. Rx fifo overflow.\n");
			/* reset rx fifo */
			{/*{{{*/
				stReg.reg = 0x0200;
				u8RegMask = 0x80;
				u8RegData = 0x00;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0214;
				u8RegMask = 0x87;
				u8RegData = 0x83;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0200;
				u8RegMask = 0x80;
				u8RegData = 0x80;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
		}/*}}}*/
		if(pstIsr->stIrqClr.b.ptz6) //rx sync
		{
			DbgString("Ptz6. Rx sync.\n");
		}
		if(pstIsr->stIrqClr.b.ptz7) //rx data error
		{/*{{{*/
			DbgString("Ptz7. Rx data error.\n");
			/* stop rx */
			{/*{{{*/
				stReg.reg = 0x0200;
				u8RegMask = 0x40;
				u8RegData = 0x00;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
			/* reset rx fifo */
			{/*{{{*/
				stReg.reg = 0x0200;
				u8RegMask = 0x80;
				u8RegData = 0x00;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0214;
				u8RegMask = 0x87;
				u8RegData = 0x83;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				stReg.reg = 0x0200;
				u8RegMask = 0x80;
				u8RegData = 0x80;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
			/* start rx */
			{/*{{{*/
				stReg.reg = 0x0200;
				u8RegMask = 0xC0;
				u8RegData = 0xC0;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
		}/*}}}*/
	}
#endif // SUPPORT_UTC
	if( (pstIsr->stIrqClr.reg[2] != 0) || pstIsr->stIrqClr.b.gpio8 ) //gpio
	{
//		Print("%02x-GPIO:%d:0x%02x\n", slvAddr COMMA pstIsr->stIrqStatus.b.gpio8 COMMA pstIsr->stIrqStatus.reg[2]);
		_SET_BIT(IRQ_GPIO, &pstIsr->stUserPoll.bitIrq);
	}
	if(pstIsr->stIrqClr.b.timer0) //periodic job 4sec
	{/*{{{*/
		Dbg("%02x-TIMER0:%d\n", slvAddr COMMA pstIsr->stIrqStatus.b.timer0);
		//ignore. don't poll user
		//_SET_BIT(IRQ_TIMER0UP, &pstIsr->stUserPoll.bitIrq);

		if(pstIsr->stJobProc.numJobStep)
		{
			if( (_TEST_BIT(JOB_DOING_CAMERA_MONITOR, &pstIsr->stJobProc.bitJobProcess)) )
			{
				//DbgString("Do TIMER0(4sec) Process camera monitoring.\n");
				PR2000_ProcessCameraMonitor(i2cFd, slvAddr, IRQ_TIMER0UP, pArg);
			}
		}
	}/*}}}*/
	if(pstIsr->stIrqClr.b.timer1) //periodic job 300msec
	{/*{{{*/
		Dbg("%02x-TIMER1:%d\n", slvAddr COMMA pstIsr->stIrqStatus.b.timer1);
		//ignore. don't poll user
		//_SET_BIT(IRQ_TIMER1UP, &pstIsr->stUserPoll.bitIrq);

		if(pstIsr->stJobProc.cntWait300MsecTime != 0)
		{
			pstIsr->stJobProc.cntWait300MsecTime--;
		}
		else
		{
			if(pstIsr->stJobProc.numJobStep)
			{
				if( ((_TEST_BIT(JOB_START_CAMERA_IN, &pstIsr->stJobProc.bitJobProcess)) && (!_TEST_BIT(JOB_DONE_CAMERA_IN, &pstIsr->stJobProc.bitJobProcess))) )
				{
					DbgString("Do TIMER1(300msec) Process camera plug in.\n");
					PR2000_ProcessCameraPlugIn(i2cFd, slvAddr, pArg);
				}

				if( ((_TEST_BIT(JOB_START_CAMERA_MONITOR, &pstIsr->stJobProc.bitJobProcess)) || (_TEST_BIT(JOB_DOING_CAMERA_MONITOR, &pstIsr->stJobProc.bitJobProcess))) )
				{
					//DbgString("Do TIMER1(300msec) Process camera monitoring.\n");
					PR2000_ProcessCameraMonitor(i2cFd, slvAddr, IRQ_TIMER1UP, pArg);
				}
			}
		}
	}/*}}}*/

	/* clr irq */
	{/*{{{*/
		PR2000_SetPage(i2cFd, slvAddr, 0);
		stReg.reg = 0x0094;
		u8RegData = pstIsr->stIrqClr.reg[0];
		if( (result = PR2000_Write(i2cFd, slvAddr, stReg.b.addr, u8RegData)) < 0)
		{
			return(result);
		}
		stReg.reg = 0x0095;
		u8RegData = pstIsr->stIrqClr.reg[1];
		if( (result = PR2000_Write(i2cFd, slvAddr, stReg.b.addr, u8RegData)) < 0)
		{
			return(result);
		}
		stReg.reg = 0x0096;
		u8RegData = pstIsr->stIrqClr.reg[2];
		if( (result = PR2000_Write(i2cFd, slvAddr, stReg.b.addr, u8RegData)) < 0)
		{
			return(result);
		}
	}/*}}}*/

	if(pstIsr->stUserPoll.bitIrq != 0)
	{
		WAKE_UP_INTERRUPTIBLE(&pHost->wqPoll);
	}

	return(result);
}

int PR2000_ReadVidStatusReg(const int i2cFd, const uint8_t slvAddr, _stPR2000_VidStatusReg *pstVidStatusReg)
{
	int result = -1;

	int i;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstVidStatusReg == NULL)
	{
		ErrorString("invalid argu\n");
		return(result);
	}

	for(i = 0; i < sizeof(_stPR2000_VidStatusReg); i++)
	{
		stReg.reg = 0x0000 + i;
		u8RegData = 0;
		if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
		{
			ErrorString("invalid page read\n");
			return(result);
		}
		pstVidStatusReg->reg[i] = u8RegData;
	}

	Dbg("0x%02x[std:%d,ref:%d,video:%d,res:%d]\n", pstVidStatusReg->reg[0] COMMA 
		pstVidStatusReg->b.det_ifmt_std COMMA
		pstVidStatusReg->b.det_ifmt_ref COMMA
		pstVidStatusReg->b.det_video COMMA
		pstVidStatusReg->b.det_ifmt_res);
#if 0
	PrintString("Det->");
	switch( pstVidStatusReg->b.det_ifmt_std )
	{
		case DET_PVI: PRINTF("PVI/"); break;
		case DET_CVI: PRINTF("CVI/"); break;
		case DET_HDA: PRINTF("HDA/"); break;
		case DET_HDT: PRINTF("HDT/"); break;
		default: break;
	}
	switch( pstVidStatusReg->b.det_ifmt_ref )
	{
		case DET_25Hz: PRINTF("25Hz/"); break;
		case DET_30Hz: PRINTF("30Hz/"); break;
		case DET_50Hz: PRINTF("50Hz/"); break;
		case DET_60Hz: PRINTF("60Hz/"); break;
		default: break;
	}
	switch( pstVidStatusReg->b.det_ifmt_res )
	{
		case DET_SD480i: PRINTF("SD480i"); break;
		case DET_SD576i: PRINTF("SD576i"); break;
		case DET_HD720p: PRINTF("HD720p"); break;
		case DET_HD1080p: PRINTF("HD1080p"); break;
		case DET_HD960p: PRINTF("HD960p"); break;
		default: break;
	}
	PRINTF("\r\n");
#endif

	Dbg("0x%02x[lock(std:%d,gain:%d,clamp:%d,hperiod:%d,hpll:%d,c_fine:%d,chroma:%d),det_chroma:%d]\n", pstVidStatusReg->reg[1] COMMA
                pstVidStatusReg->b.lock_std COMMA
                pstVidStatusReg->b.lock_gain COMMA
                pstVidStatusReg->b.lock_clamp COMMA
                pstVidStatusReg->b.lock_hperiod COMMA
                pstVidStatusReg->b.lock_hpll COMMA
                pstVidStatusReg->b.lock_c_fine COMMA
                pstVidStatusReg->b.lock_chroma COMMA
                pstVidStatusReg->b.det_chroma);

	Dbg("0x%02x[det(hdtv:%d,hdth1:%d,hdth0:%d,hda:%d)]\n", pstVidStatusReg->reg[2] COMMA
                pstVidStatusReg->b.det_std_hdt_v COMMA
                pstVidStatusReg->b.det_std_hdt_h1 COMMA
                pstVidStatusReg->b.det_std_hdt_h0 COMMA
                pstVidStatusReg->b.det_std_hda);

	return(result);
}

int PR2000_ReadStdResol(const int i2cFd, const uint8_t slvAddr, const _stPR2000_VidStatusReg *pstVidStatusReg, enum _eCameraStandard *pCameraStandard, enum _eCameraResolution *pCameraResolution, enum _eVideoResolution *pVideoResolution)
{
	int result = -1;

	enum _eCameraStandard cameraStandard;
	enum _eCameraResolution cameraResolution;
	enum _eVideoResolution videoResolution;

	if(pstVidStatusReg == NULL)
	{
		ErrorString("invalid argu\n");
		return(result);
	}

	Dbg("0x%02x[std:%d,ref:%d,video:%d,res:%d]\n", pstVidStatusReg->reg[0] COMMA 
		pstVidStatusReg->b.det_ifmt_std COMMA
		pstVidStatusReg->b.det_ifmt_ref COMMA
		pstVidStatusReg->b.det_video COMMA
		pstVidStatusReg->b.det_ifmt_res);
#if 0
	PrintString("Det->");
	switch( pstVidStatusReg->b.det_ifmt_std )
	{
		case DET_PVI: PRINTF("PVI/"); break;
		case DET_CVI: PRINTF("CVI/"); break;
		case DET_HDA: PRINTF("HDA/"); break;
		case DET_HDT: PRINTF("HDT/"); break;
		default: break;
	}
	switch( pstVidStatusReg->b.det_ifmt_ref )
	{
		case DET_25Hz: PRINTF("25Hz/"); break;
		case DET_30Hz: PRINTF("30Hz/"); break;
		case DET_50Hz: PRINTF("50Hz/"); break;
		case DET_60Hz: PRINTF("60Hz/"); break;
		default: break;
	}
	switch( pstVidStatusReg->b.det_ifmt_res )
	{
		case DET_SD480i: PRINTF("SD480i"); break;
		case DET_SD576i: PRINTF("SD576i"); break;
		case DET_HD720p: PRINTF("HD720p"); break;
		case DET_HD1080p: PRINTF("HD1080p"); break;
		case DET_HD960p: PRINTF("HD960p"); break;
		default: break;
	}
	PRINTF("\r\n");
#endif
	Dbg("0x%02x[lock(std:%d,gain:%d,clamp:%d,hperiod:%d,hpll:%d,c_fine:%d,chroma:%d),det_chroma:%d]\n", pstVidStatusReg->reg[1] COMMA
                pstVidStatusReg->b.lock_std COMMA
                pstVidStatusReg->b.lock_gain COMMA
                pstVidStatusReg->b.lock_clamp COMMA
                pstVidStatusReg->b.lock_hperiod COMMA
                pstVidStatusReg->b.lock_hpll COMMA
                pstVidStatusReg->b.lock_c_fine COMMA
                pstVidStatusReg->b.lock_chroma COMMA
                pstVidStatusReg->b.det_chroma);

	Dbg("0x%02x[det(hdtv:%d,hdth1:%d,hdth0:%d,hda:%d)]\n", pstVidStatusReg->reg[2] COMMA
                pstVidStatusReg->b.det_std_hdt_v COMMA
                pstVidStatusReg->b.det_std_hdt_h1 COMMA
                pstVidStatusReg->b.det_std_hdt_h0 COMMA
                pstVidStatusReg->b.det_std_hda);

	switch( pstVidStatusReg->b.det_ifmt_res )
	{/*{{{*/
		case DET_SD480i: 
			{
				cameraStandard = SD; 
				cameraResolution = camera_ntsc; 
			}
			break;
		case DET_SD576i: 
			{
				cameraStandard = SD; 
				cameraResolution = camera_pal; 
			}
			break;
		case DET_HD720p:
		case DET_HD1080p:
		case DET_HD960p:
			{
				switch( pstVidStatusReg->b.det_ifmt_std )
				{
					case DET_PVI: cameraStandard = PVI; break;
					case DET_CVI: cameraStandard = CVI; break;
					case DET_HDA: cameraStandard = HDA; break;
					case DET_HDT: cameraStandard = HDT_NEW; break;
					default: cameraStandard = PVI; break;
				}
			}
			break;
		default:
			{
				cameraStandard = PVI; 
			}
			break;
	}/*}}}*/

	if(cameraStandard != SD)
	{/*{{{*/
		switch( pstVidStatusReg->b.det_ifmt_res )
		{
			case DET_HD720p:
				{
					switch( pstVidStatusReg->b.det_ifmt_ref )
					{
						case DET_25Hz: cameraResolution = camera_1280x720p25; break;
						case DET_30Hz: cameraResolution = camera_1280x720p30; break;
						case DET_50Hz: cameraResolution = camera_1280x720p50; break;
						case DET_60Hz: cameraResolution = camera_1280x720p60; break;
						default: cameraResolution = camera_1280x720p25; break;
					}
				}
				break;
			case DET_HD1080p:
				{
					switch( pstVidStatusReg->b.det_ifmt_ref )
					{
						case DET_25Hz: cameraResolution = camera_1920x1080p25; break;
						case DET_30Hz: cameraResolution = camera_1920x1080p30; break;
						case DET_50Hz:
						case DET_60Hz:
						default: cameraResolution = camera_1920x1080p25; break;
					}
				}
				break;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
			case DET_HD960p: 
				{
					switch( pstVidStatusReg->b.det_ifmt_ref )
					{
						case DET_25Hz: cameraResolution = camera_1280x800p25; break;
						case DET_30Hz: cameraResolution = camera_1280x800p30; break;
						case DET_50Hz: cameraResolution = camera_1280x800p50; break;
						case DET_60Hz: cameraResolution = camera_1280x800p60; break;
						default: cameraResolution = camera_1280x800p25; break;
					}
				}
				break;
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
			case DET_HD960p: 
				{
					switch( pstVidStatusReg->b.det_ifmt_ref )
					{
						case DET_25Hz: cameraResolution = camera_1280x960p25; break;
						case DET_30Hz: cameraResolution = camera_1280x960p30; break;
						case DET_50Hz: cameraResolution = camera_1280x960p50; break;
						case DET_60Hz: cameraResolution = camera_1280x960p60; break;
						default: cameraResolution = camera_1280x960p25; break;
					}
				}
				break;
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
			default:
				{
					cameraResolution = camera_1280x720p25;
				}
				break;
		}
	}/*}}}*/

	if(pCameraStandard) *pCameraStandard = cameraStandard;
	if(pCameraResolution) *pCameraResolution = cameraResolution;
	videoResolution = stDefaultCameraVideoRelation[cameraResolution].eVideoResolution;
	if(pVideoResolution) *pVideoResolution = videoResolution;

	return(0);
}

int PR2000_GetStdResol(const int i2cFd, const uint8_t slvAddr, _stPR2000_VidStatusReg *pstVidStatusReg, enum _eCameraStandard *pCameraStandard, enum _eCameraResolution *pCameraResolution, enum _eVideoResolution *pVideoResolution, int *pReJudge)
{
	int result = -1;

	enum _eCameraStandard cameraStandard;
	enum _eCameraResolution cameraResolution;
	enum _eVideoResolution videoResolution;
	int reJudge = 0;

	if(pstVidStatusReg == NULL)
	{
		ErrorString("invalid argu\n");
		return(result);
	}

	Dbg("0x%02x[std:%d,ref:%d,video:%d,res:%d]\n", pstVidStatusReg->reg[0] COMMA 
		pstVidStatusReg->b.det_ifmt_std COMMA
		pstVidStatusReg->b.det_ifmt_ref COMMA
		pstVidStatusReg->b.det_video COMMA
		pstVidStatusReg->b.det_ifmt_res);
#if 0
	PrintString("Det->");
	switch( pstVidStatusReg->b.det_ifmt_std )
	{
		case DET_PVI: PRINTF("PVI/"); break;
		case DET_CVI: PRINTF("CVI/"); break;
		case DET_HDA: PRINTF("HDA/"); break;
		case DET_HDT: PRINTF("HDT/"); break;
		default: break;
	}
	switch( pstVidStatusReg->b.det_ifmt_ref )
	{
		case DET_25Hz: PRINTF("25Hz/"); break;
		case DET_30Hz: PRINTF("30Hz/"); break;
		case DET_50Hz: PRINTF("50Hz/"); break;
		case DET_60Hz: PRINTF("60Hz/"); break;
		default: break;
	}
	switch( pstVidStatusReg->b.det_ifmt_res )
	{
		case DET_SD480i: PRINTF("SD480i"); break;
		case DET_SD576i: PRINTF("SD576i"); break;
		case DET_HD720p: PRINTF("HD720p"); break;
		case DET_HD1080p: PRINTF("HD1080p"); break;
		case DET_HD960p: PRINTF("HD960p"); break;
		default: break;
	}
	PRINTF("\r\n");
#endif
	Dbg("0x%02x[lock(std:%d,gain:%d,clamp:%d,hperiod:%d,hpll:%d,c_fine:%d,chroma:%d),det_chroma:%d]\n", pstVidStatusReg->reg[1] COMMA
                pstVidStatusReg->b.lock_std COMMA
                pstVidStatusReg->b.lock_gain COMMA
                pstVidStatusReg->b.lock_clamp COMMA
                pstVidStatusReg->b.lock_hperiod COMMA
                pstVidStatusReg->b.lock_hpll COMMA
                pstVidStatusReg->b.lock_c_fine COMMA
                pstVidStatusReg->b.lock_chroma COMMA
                pstVidStatusReg->b.det_chroma);

	Dbg("0x%02x[det(hdtv:%d,hdth1:%d,hdth0:%d,hda:%d)]\n", pstVidStatusReg->reg[2] COMMA
                pstVidStatusReg->b.det_std_hdt_v COMMA
                pstVidStatusReg->b.det_std_hdt_h1 COMMA
                pstVidStatusReg->b.det_std_hdt_h0 COMMA
                pstVidStatusReg->b.det_std_hda);

	switch( pstVidStatusReg->b.det_ifmt_res )
	{/*{{{*/
		case DET_SD480i: 
			{
				cameraStandard = SD; 
				cameraResolution = camera_ntsc; 
			}
			break;
		case DET_SD576i: 
			{
				cameraStandard = SD; 
				cameraResolution = camera_pal; 
			}
			break;
		case DET_HD720p:
		case DET_HD1080p:
		case DET_HD960p:
			{
				switch( pstVidStatusReg->b.det_ifmt_std )
				{
					case DET_PVI: cameraStandard = PVI; break;
					case DET_CVI: cameraStandard = CVI; break;
					case DET_HDA: cameraStandard = HDA; break;
					case DET_HDT: cameraStandard = HDT_NEW; break;
					default: cameraStandard = PVI; break;
				}
			}
			break;
		default:
			{
				cameraStandard = PVI; 
			}
			break;
	}/*}}}*/

	if(cameraStandard != SD)
	{/*{{{*/
		switch( pstVidStatusReg->b.det_ifmt_res )
		{
			case DET_HD720p:
				{
					switch( pstVidStatusReg->b.det_ifmt_ref )
					{
						case DET_25Hz: cameraResolution = camera_1280x720p25; break;
						case DET_30Hz: cameraResolution = camera_1280x720p30; break;
						case DET_50Hz: cameraResolution = camera_1280x720p50; break;
						case DET_60Hz: cameraResolution = camera_1280x720p60; break;
						default: cameraResolution = camera_1280x720p25; break;
					}
				}
				break;
			case DET_HD1080p:
				{
					switch( pstVidStatusReg->b.det_ifmt_ref )
					{
						case DET_25Hz: cameraResolution = camera_1920x1080p25; break;
						case DET_30Hz: cameraResolution = camera_1920x1080p30; break;
						case DET_50Hz:
						case DET_60Hz:
						default: cameraResolution = camera_1920x1080p25; break;
					}
				}
				break;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
			case DET_HD960p: 
				{
					switch( pstVidStatusReg->b.det_ifmt_ref )
					{
						case DET_25Hz: cameraResolution = camera_1280x800p25; break;
						case DET_30Hz: cameraResolution = camera_1280x800p30; break;
						case DET_50Hz: cameraResolution = camera_1280x800p50; break;
						case DET_60Hz: cameraResolution = camera_1280x800p60; break;
						default: cameraResolution = camera_1280x800p25; break;
					}
				}
				break;
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
			case DET_HD960p: 
				{
					switch( pstVidStatusReg->b.det_ifmt_ref )
					{
						case DET_25Hz: cameraResolution = camera_1280x960p25; break;
						case DET_30Hz: cameraResolution = camera_1280x960p30; break;
						case DET_50Hz: cameraResolution = camera_1280x960p50; break;
						case DET_60Hz: cameraResolution = camera_1280x960p60; break;
						default: cameraResolution = camera_1280x960p25; break;
					}
				}
				break;
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
			default:
				{
					cameraResolution = camera_1280x720p25;
				}
				break;
		}
	}/*}}}*/

	/* check hdt - 720p old/new standard */
	if( (cameraStandard == HDT_NEW) && ((cameraResolution == camera_1280x720p25) || (cameraResolution == camera_1280x720p30)) )
	{
		if( (pstVidStatusReg->b.det_std_hdt_v == 1) && (pstVidStatusReg->b.det_std_hdt_h1 == 1) && (pstVidStatusReg->b.det_std_hdt_h0 == 1) )
		{
			cameraStandard = HDT_NEW;
		}
		else if( (pstVidStatusReg->b.det_std_hdt_v == 1) && (pstVidStatusReg->b.det_std_hdt_h1 == 0) && (pstVidStatusReg->b.det_std_hdt_h0 == 1) )
		{
			cameraStandard = HDT_OLD;
		}
		else
		{
			Error("invalid hdt flag(%02x)\n", pstVidStatusReg->reg[2]);
			cameraStandard = HDT_NEW;
			return(-1);
		}
	}
	/* check hda - 1080p standard */
	else if( (cameraStandard == HDA) )
	{
		if( ((cameraResolution == camera_1920x1080p25) || (cameraResolution == camera_1920x1080p30)) )
		{
			if( (pstVidStatusReg->b.det_std_hda == 1) )
			{
				cameraStandard = HDA;
			}
			else
			{
				cameraStandard = CVI; // reJudge CVI
				reJudge = 1;
			}
		}
	}

	if(pCameraStandard) *pCameraStandard = cameraStandard;
	if(pCameraResolution) *pCameraResolution = cameraResolution;
	videoResolution = stDefaultCameraVideoRelation[cameraResolution].eVideoResolution;
	if(pVideoResolution) *pVideoResolution = videoResolution;
	if(pReJudge) *pReJudge = reJudge;

	return(0);
}

#ifdef SUPPORT_VID
int PR2000_VID_SetChnAttr(const int i2cFd, const uint8_t slvAddr, const _stChnAttr *pstChnAttr)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;
	uint8_t u8RegMask;

	if(pstChnAttr == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//uint16_t u16HActive; //b[12:0]
	stReg.reg = 0x0112;
	u8RegData = (pstChnAttr->u16HActive >> 8)&0x1F;
	u8RegMask = 0x1F;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	stReg.reg = 0x0114;
	u8RegData = pstChnAttr->u16HActive & 0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	//uint16_t u16HDelay; //b[12:0]
	stReg.reg = 0x0111;
	u8RegData = (pstChnAttr->u16HDelay >> 8)&0x1F;
	u8RegMask = 0x1F;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	stReg.reg = 0x0113;
	u8RegData = pstChnAttr->u16HDelay & 0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	//uint16_t u16VActive; //b[10:0]
	stReg.reg = 0x0112;
	u8RegData = ((pstChnAttr->u16VActive >> 8)&0x07) << 5;
	u8RegMask = 0xE0;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	stReg.reg = 0x0116;
	u8RegData = pstChnAttr->u16VActive & 0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	//uint16_t u16VDelay; //b[10:0]
	stReg.reg = 0x0111;
	u8RegData = ((pstChnAttr->u16VDelay >> 8)&0x07) << 5;
	u8RegMask = 0xE0;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	stReg.reg = 0x0115;
	u8RegData = pstChnAttr->u16VDelay & 0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	if(pstChnAttr->u16HSCLRatio != 0)
	{
		stReg.reg = 0x0129;
		u8RegData = pstChnAttr->u16HSCLRatio>>8;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("Write reg.\n");
			return(-1);
		}

		stReg.reg = 0x012A;
		u8RegData = pstChnAttr->u16HSCLRatio & 0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("Write reg.\n");
			return(-1);
		}
	}

	return(result);
}

int PR2000_VID_GetChnAttr(const int i2cFd, const uint8_t slvAddr, _stChnAttr *pstChnAttr)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData = 0;
	uint8_t u8RegMask;

	if(pstChnAttr == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//uint16_t u16HActive; //b[12:0]
	stReg.reg = 0x0112;
	u8RegMask = 0x1F;
	if( (result = PR2000_PageReadMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstChnAttr->u16HActive = (u8RegData&0x1F)<<8;

	stReg.reg = 0x0114;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstChnAttr->u16HActive |= u8RegData;

	//uint16_t u16HDelay; //b[12:0]
	stReg.reg = 0x0111;
	u8RegMask = 0x1F;
	if( (result = PR2000_PageReadMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstChnAttr->u16HDelay = (u8RegData&0x1F)<<8;

	stReg.reg = 0x0113;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstChnAttr->u16HDelay |= u8RegData;

	//uint16_t u16VActive; //b[10:0]
	stReg.reg = 0x0112;
	u8RegMask = 0xE0;
	if( (result = PR2000_PageReadMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstChnAttr->u16VActive = (u8RegData>>5)<<8;

	stReg.reg = 0x0116;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstChnAttr->u16VActive |= u8RegData;

	//uint16_t u16VDelay; //b[10:0]
	stReg.reg = 0x0111;
	u8RegMask = 0x1F;
	if( (result = PR2000_PageReadMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstChnAttr->u16VDelay = (u8RegData>>5)<<8;

	stReg.reg = 0x0115;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstChnAttr->u16VDelay |= u8RegData;

	stReg.reg = 0x0129;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstChnAttr->u16HSCLRatio = u8RegData<<8;

	stReg.reg = 0x012A;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstChnAttr->u16HSCLRatio |= u8RegData;

	return(result);
}

int PR2000_VID_SetCscAttr(const int i2cFd, const uint8_t slvAddr, const _stCscAttr *pstCscAttr)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstCscAttr == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//u8CbGain;
	stReg.reg = 0x0124;
	u8RegData = pstCscAttr->u8CbGain;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	//u8CrGain;
	stReg.reg = 0x0125;
	u8RegData = pstCscAttr->u8CrGain;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	//u8CbOffset;
	stReg.reg = 0x0126;
	u8RegData = pstCscAttr->u8CbOffset;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	//u8CrOffset;
	stReg.reg = 0x0127;
	u8RegData = pstCscAttr->u8CrOffset;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	return(result);
}

int PR2000_VID_GetCscAttr(const int i2cFd, const uint8_t slvAddr, _stCscAttr *pstCscAttr)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstCscAttr == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//u8CbGain;
	stReg.reg = 0x0124;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstCscAttr->u8CbGain = u8RegData;

	//u8CrGain;
	stReg.reg = 0x0125;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstCscAttr->u8CrGain = u8RegData;

	//u8CbOffset;
	stReg.reg = 0x0126;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstCscAttr->u8CbOffset = u8RegData;

	//u8CrOffset;
	stReg.reg = 0x0127;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstCscAttr->u8CrOffset = u8RegData;

	return(result);
}

int PR2000_VID_SetContrast(const int i2cFd, const uint8_t slvAddr, const _stContrast *pstContrast)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstContrast == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//Contrast
	stReg.reg = 0x0120;
	u8RegData = pstContrast->u8Contrast;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	return(result);
}

int PR2000_VID_GetContrast(const int i2cFd, const uint8_t slvAddr, _stContrast *pstContrast)
{

	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstContrast == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//Contrast
	stReg.reg = 0x0120;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstContrast->u8Contrast = u8RegData;

	return(result);
}

int PR2000_VID_SetBright(const int i2cFd, const uint8_t slvAddr, const _stBright *pstBright)
{

	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstBright == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//Bright
	stReg.reg = 0x0121;
	u8RegData = pstBright->u8Bright;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	return(result);
}

int PR2000_VID_GetBright(const int i2cFd, const uint8_t slvAddr, _stBright *pstBright)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstBright == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//Bright
	stReg.reg = 0x0121;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstBright->u8Bright = u8RegData;

	return(result);
}

int PR2000_VID_SetSaturation(const int i2cFd, const uint8_t slvAddr, const _stSaturation *pstSaturation)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstSaturation == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//Saturation
	stReg.reg = 0x0122;
	u8RegData = pstSaturation->u8Saturation;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	return(result);
}

int PR2000_VID_GetSaturation(const int i2cFd, const uint8_t slvAddr, _stSaturation *pstSaturation)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstSaturation == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//Saturation
	stReg.reg = 0x0122;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstSaturation->u8Saturation = u8RegData;

	return(result);
}

int PR2000_VID_SetHue(const int i2cFd, const uint8_t slvAddr, const _stHue *pstHue)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstHue == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//Hue
	stReg.reg = 0x0123;
	u8RegData = pstHue->u8Hue;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	return(result);
}

int PR2000_VID_GetHue(const int i2cFd, const uint8_t slvAddr, _stHue *pstHue)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	if(pstHue == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//Hue
	stReg.reg = 0x0123;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	pstHue->u8Hue = u8RegData;

	return(result);
}

int PR2000_VID_SetSharpness(const int i2cFd, const uint8_t slvAddr, const _stSharpness *pstSharpness)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;
	uint8_t u8RegMask;

	if(pstSharpness == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//Sharpness
	stReg.reg = 0x0139;
	u8RegMask = 0x0F;
	u8RegData = pstSharpness->u8Sharpness & 0xF;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	return(result);
}

int PR2000_VID_GetSharpness(const int i2cFd, const uint8_t slvAddr, _stSharpness *pstSharpness)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData = 0;
	uint8_t u8RegMask;

	if(pstSharpness == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	//Sharpness
	stReg.reg = 0x0139;
	u8RegMask = 0x0F;
	if( (result = PR2000_PageReadMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}

	pstSharpness->u8Sharpness = u8RegData&0xF;

	return(result);
}

int PR2000_VID_SetBlank(const int i2cFd, const uint8_t slvAddr, const int bEnable, const int blankColor)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData = 0;
	uint8_t u8RegMask;

	/* blank */
	stReg.reg = 0x0100;
	u8RegMask = 0x03;
	u8RegData = ((bEnable&1)<<1) | (blankColor&1); //0:normal video output, 1:manual background mode
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("Write reg.\n");
		return(-1);
	}

	return(result);
}
#endif // SUPPORT_VID

int PR2000_GetNovidStatus(const int i2cFd, const uint8_t slvAddr, uint8_t *pStatus)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData = 0;

	if(pStatus == NULL)
	{
		ErrorString("Invalid argu.\n");
		return(-1);
	}

	/* IRQ Status */
	stReg.reg = 0x0099;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}
	*pStatus = (u8RegData>>4)&1;

	return(result);
}



#ifdef SUPPORT_UTC
static int PR2000_UTC_WriteFlagFifo(const int i2cFd, const uint8_t slvAddr, const int sizeArray, const uint8_t *pData)
{
	int result = -1;

	int i;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;

	for(i = 0; i < sizeArray; i++)
	{
		Dbg("i:%d, data:0x%02x\n", i COMMA pData[i]);
		stReg.reg = 0x0211;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, pData[i])) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
	}

	/* verify utc data count */
	stReg.reg = 0x0213;
	u8RegData = 0;
	if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
	{
		ErrorString("invalid page read\n");
		return(result);
	}
	if(sizeArray != u8RegData+1)
	{
		Error("invalid utc data count(%d-%d)\n", sizeArray COMMA u8RegData);
		return(-1);
	}
	return(sizeArray);
}

static int PR2000_UTC_SendTxFifo(const int i2cFd, const uint8_t slvAddr, const enum _eCameraStandard cameraStandard, const enum _eCameraResolution cameraResolution, const int dataSize, const uint8_t *pData)
{
	int result = -1;

	int i;
	_stPR2000_Reg stReg;
	uint8_t u8RegMask;
	uint8_t u8RegData;

	Print("%02x-standrad:%d, size:%d, data0:0x%02x\n", slvAddr COMMA cameraStandard COMMA dataSize COMMA pData[0]);
	Dbg("%02x-senddata[size:%d]:\n", slvAddr COMMA dataSize);
	for(i = 0; i < dataSize; i++)
	{
		PRINTF("0x%02x ", pData[i]);
	}
	PRINTF("\r\n");
	switch(cameraStandard)
	{
		case SD:
			{/*{{{*/
				DbgString("utc SD\n");
				for(i = 0; i < dataSize; i++)
				{
					Dbg("i:%d, data:0x%02x\n", i COMMA pData[i]);
					stReg.reg = 0x0211;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, pData[i])) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}

					if( (i != 0) && (((i+1) % PR2000_UTC_SD_TXCMD_BASE_BYTE_CNT)==0) )
					{
						/* verify utc data count */
						stReg.reg = 0x0212;
						u8RegData = 0;
						if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
						{
							ErrorString("invalid page read\n");
							return(result);
						}
						if((PR2000_UTC_SD_TXCMD_BASE_BYTE_CNT) != (u8RegData))
						{
							Error("invalid utc data count(%d-%d)\n", PR2000_UTC_SD_TXCMD_BASE_BYTE_CNT COMMA u8RegData);
							return(-1);
						}

						Dbg("Send & Wait %dByte\n", PR2000_UTC_SD_TXCMD_BASE_BYTE_CNT);
						/* start utc send */
						stReg.reg = 0x0220;
						u8RegMask = 0x40;
						u8RegData = 0x40;
						if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
						{
							ErrorString("invalid page write\n");
							return(result);
						}

						/* wait complete sending */
						{/*{{{*/
							int retryCnt = 10;
							uint8_t u8TxFifoCnt = 0;
							uint8_t u8TxBusy = 0;
							do
							{/*{{{*/
								stReg.reg = 0x0212;
								PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxFifoCnt);

								stReg.reg = 0x0098;
								PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxBusy);
								u8TxBusy &= 0x01;
								Dbg("txBusy:%02x\n", u8TxBusy);

								if( (u8TxFifoCnt == 0) && (u8TxBusy == 0) ) break;
								else
								{
									msleep(100);
									if(retryCnt <= 0) 
									{
										Error("txBusy:%02x\n", u8TxBusy);
										return(-1);
									}
								}
							} while(retryCnt--);/*}}}*/
						}/*}}}*/
					}
				}
			}/*}}}*/
			break;
#if defined(SUPPORT_STD_PVI)
		case PVI:
			{/*{{{*/
				DbgString("utc PVI\n");
				for(i = 0; i < dataSize; i++)
				{
					Dbg("i:%d, data:0x%02x\n", i COMMA pData[i]);
					stReg.reg = 0x0211;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, pData[i])) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}

					if( (i != 0) && (((i+1) % PR2000_UTC_PVI_TXCMD_BASE_BYTE_CNT)==0) )
					{
						/* verify utc data count */
						stReg.reg = 0x0212;
						u8RegData = 0;
						if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
						{
							ErrorString("invalid page read\n");
							return(result);
						}
						if((PR2000_UTC_PVI_TXCMD_BASE_BYTE_CNT) != (u8RegData))
						{
							Error("invalid utc data count(%d-%d)\n", PR2000_UTC_PVI_TXCMD_BASE_BYTE_CNT COMMA u8RegData);
							return(-1);
						}

						Dbg("Send & Wait %dByte\n", PR2000_UTC_PVI_TXCMD_BASE_BYTE_CNT);
						/* start utc send */
						stReg.reg = 0x0220;
						u8RegMask = 0x40;
						u8RegData = 0x40;
						if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
						{
							ErrorString("invalid page write\n");
							return(result);
						}

						/* wait complete sending */
						{/*{{{*/
							int retryCnt = 10;
							uint8_t u8TxFifoCnt = 0;
							uint8_t u8TxBusy = 0;
							do
							{/*{{{*/
								stReg.reg = 0x0212;
								PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxFifoCnt);

								stReg.reg = 0x0098;
								PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxBusy);
								u8TxBusy &= 0x01;
								Dbg("txBusy:%02x\n", u8TxBusy);

								if( (u8TxFifoCnt == 0) && (u8TxBusy == 0) ) break;
								else
								{
									msleep(100);
									if(retryCnt <= 0) 
									{
										Error("txBusy:%02x\n", u8TxBusy);
										return(-1);
									}
								}
							} while(retryCnt--);/*}}}*/
						}/*}}}*/
					}
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_PVI)
#if defined(SUPPORT_STD_HDA)
		case HDA:
			{
				DbgString("utc HDA\n");
				if(cameraResolution >= camera_1920x1080p30)
				{/*{{{*/
					for(i = 0; i < dataSize; i++)
					{
						Dbg("i:%d, data:0x%02x\n", i COMMA pData[i]);
						stReg.reg = 0x0211;
						if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, pData[i])) < 0)
						{
							ErrorString("invalid page write\n");
							return(result);
						}

						if( (i != 0) && (((i+1) % PR2000_UTC_HDA_TXCMD_BASE_BYTE_CNT_1080p)==0) )
						{
							/* verify utc data count */
							stReg.reg = 0x0212;
							u8RegData = 0;
							if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
							{
								ErrorString("invalid page read\n");
								return(result);
							}
							if((PR2000_UTC_HDA_TXCMD_BASE_BYTE_CNT_1080p) != (u8RegData))
							{
								Error("invalid utc data count(%d-%d)\n", PR2000_UTC_HDA_TXCMD_BASE_BYTE_CNT_1080p COMMA u8RegData);
								return(-1);
							}

							Dbg("Send & Wait %dByte\n", PR2000_UTC_HDA_TXCMD_BASE_BYTE_CNT_1080p);
							/* start utc send */
							stReg.reg = 0x0220;
							u8RegMask = 0x40;
							u8RegData = 0x40;
							if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
							{
								ErrorString("invalid page write\n");
								return(result);
							}

							/* wait complete sending */
							{/*{{{*/
								int retryCnt = 10;
								uint8_t u8TxFifoCnt = 0;
								uint8_t u8TxBusy = 0;
								do
								{/*{{{*/
									stReg.reg = 0x0212;
									PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxFifoCnt);

									stReg.reg = 0x0098;
									PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxBusy);
									u8TxBusy &= 0x01;
									Dbg("txBusy:%02x\n", u8TxBusy);

									if( (u8TxFifoCnt == 0) && (u8TxBusy == 0) ) break;
									else
									{
										msleep(100);
										if(retryCnt <= 0) 
										{
											Error("txBusy:%02x\n", u8TxBusy);
											return(-1);
										}
									}
								} while(retryCnt--);/*}}}*/
							}/*}}}*/
						}
					}
				}/*}}}*/
				else
				{/*{{{*/
					for(i = 0; i < dataSize; i++)
					{
						Dbg("i:%d, data:0x%02x\n", i COMMA pData[i]);
						stReg.reg = 0x0211;
						if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, pData[i])) < 0)
						{
							ErrorString("invalid page write\n");
							return(result);
						}

						if( (i != 0) && (((i+1) % PR2000_UTC_HDA_TXCMD_BASE_BYTE_CNT_720p)==0) )
						{
							/* verify utc data count */
							stReg.reg = 0x0212;
							u8RegData = 0;
							if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
							{
								ErrorString("invalid page read\n");
								return(result);
							}
							if((PR2000_UTC_HDA_TXCMD_BASE_BYTE_CNT_720p) != (u8RegData))
							{
								Error("invalid utc data count(%d-%d)\n", PR2000_UTC_HDA_TXCMD_BASE_BYTE_CNT_720p COMMA u8RegData);
								return(-1);
							}

							Dbg("Send & Wait %dByte\n", PR2000_UTC_HDA_TXCMD_BASE_BYTE_CNT_720p);
							/* start utc send */
							stReg.reg = 0x0220;
							u8RegMask = 0x40;
							u8RegData = 0x40;
							if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
							{
								ErrorString("invalid page write\n");
								return(result);
							}

							/* wait complete sending */
							{/*{{{*/
								int retryCnt = 10;
								uint8_t u8TxFifoCnt = 0;
								uint8_t u8TxBusy = 0;
								do
								{/*{{{*/
									stReg.reg = 0x0212;
									PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxFifoCnt);

									stReg.reg = 0x0098;
									PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxBusy);
									u8TxBusy &= 0x01;
									Dbg("txBusy:%02x\n", u8TxBusy);

									if( (u8TxFifoCnt == 0) && (u8TxBusy == 0) ) break;
									else
									{
										msleep(100);
										if(retryCnt <= 0) 
										{
											Error("txBusy:%02x\n", u8TxBusy);
											return(-1);
										}
									}
								} while(retryCnt--);/*}}}*/
							}/*}}}*/
						}
					}
				}/*}}}*/
			}
			break;
#endif //defined(SUPPORT_STD_HDA)
#if defined(SUPPORT_STD_CVI)
		case CVI:
			{/*{{{*/
                        	uint8_t bitCnt = 0;
	                        uint8_t evenParity = 0;

				DbgString("utc CVI\n");

				for(i = 0; i < dataSize; i++)
				{
					Dbg("i:%d, data:0x%02x\n", i COMMA pData[i]);
					stReg.reg = 0x0211;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, pData[i])) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}

					/* append parity data */
					for(evenParity = 0, bitCnt = 0; bitCnt < 8; bitCnt++)
					{     
						if(pData[i] & (1<<bitCnt)) evenParity++;
					}     
					u8RegData = ((evenParity&0x1))|0xFE;

					stReg.reg = 0x0211;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}

					if( (i != 0) && (((i+1) % PR2000_UTC_CVI_TXCMD_BASE_BYTE_CNT)==0) )
					{
						/* verify utc data count */
						stReg.reg = 0x0212;
						u8RegData = 0;
						if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
						{
							ErrorString("invalid page read\n");
							return(result);
						}
						if((PR2000_UTC_CVI_TXCMD_BASE_BYTE_CNT) != (u8RegData/2))
						{
							Error("invalid utc data count(%d-%d)\n", PR2000_UTC_CVI_TXCMD_BASE_BYTE_CNT COMMA u8RegData);
							return(-1);
						}

						Dbg("Send & Wait %dByte\n", PR2000_UTC_CVI_TXCMD_BASE_BYTE_CNT);
						/* start utc send */
						stReg.reg = 0x0220;
						u8RegMask = 0x40;
						u8RegData = 0x40;
						if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
						{
							ErrorString("invalid page write\n");
							return(result);
						}

						/* wait complete sending */
						{/*{{{*/
							int retryCnt = 10;
							uint8_t u8TxFifoCnt = 0;
							uint8_t u8TxBusy = 0;
							do
							{/*{{{*/
								stReg.reg = 0x0212;
								PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxFifoCnt);

								stReg.reg = 0x0098;
								PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxBusy);
								u8TxBusy &= 0x01;
								Dbg("txBusy:%02x\n", u8TxBusy);

								if( (u8TxFifoCnt == 0) && (u8TxBusy == 0) ) break;
								else
								{
									msleep(100);
									if(retryCnt <= 0) 
									{
										Error("txBusy:%02x\n", u8TxBusy);
										return(-1);
									}
								}
							} while(retryCnt--);/*}}}*/
						}/*}}}*/
					}
				}

			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_CVI)
#if defined(SUPPORT_STD_HDT)
		case HDT_OLD:
		case HDT_NEW:
			{/*{{{*/
				DbgString("utc HDT\n");
				for(i = 0; i < dataSize; i++)
				{
					Dbg("i:%d, data:0x%02x\n", i COMMA pData[i]);
					stReg.reg = 0x0211;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, pData[i])) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}

					if( (i != 0) && (((i+1) % PR2000_UTC_HDT_TXCMD_BASE_BYTE_CNT)==0) )
					{
						/* verify utc data count */
						stReg.reg = 0x0212;
						u8RegData = 0;
						if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
						{
							ErrorString("invalid page read\n");
							return(result);
						}
						if((PR2000_UTC_HDT_TXCMD_BASE_BYTE_CNT) != (u8RegData))
						{
							Error("invalid utc data count(%d-%d)\n", PR2000_UTC_HDT_TXCMD_BASE_BYTE_CNT COMMA u8RegData);
							return(-1);
						}

						Dbg("Send & Wait %dByte\n", PR2000_UTC_HDT_TXCMD_BASE_BYTE_CNT);
						/* start utc send */
						stReg.reg = 0x0220;
						u8RegMask = 0x40;
						u8RegData = 0x40;
						if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
						{
							ErrorString("invalid page write\n");
							return(result);
						}

						/* wait complete sending */
						{/*{{{*/
							int retryCnt = 10;
							uint8_t u8TxFifoCnt = 0;
							uint8_t u8TxBusy = 0;
							do
							{/*{{{*/
								stReg.reg = 0x0212;
								PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxFifoCnt);

								stReg.reg = 0x0098;
								PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8TxBusy);
								u8TxBusy &= 0x01;
								Dbg("txBusy:%02x\n", u8TxBusy);

								if( (u8TxFifoCnt == 0) && (u8TxBusy == 0) ) break;
								else
								{
									msleep(100);
									if(retryCnt <= 0) 
									{
										Error("txBusy:%02x\n", u8TxBusy);
										return(-1);
									}
								}
							} while(retryCnt--);/*}}}*/
						}/*}}}*/
					}
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_HDT)
		default:
			{
				ErrorString("Invalid standard\n");
				result = -1;
			}
			break;
	}


	return(dataSize);
}

int PR2000_UTC_SetTable(const int i2cFd, const uint8_t slvAddr, const enum _eCameraStandard cameraStandard, const enum _eCameraResolution cameraResolution)
{
	int result = -1;
	const _stPR2000_Table_STD_HD_CameraResolution *pTblSTD_UTCHD = NULL;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	const _stPR2000_Table_EXT_HD_CameraResolution *pTblEXT_UTCHD = NULL;
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	const _stPR2000_Table_SD_CameraResolution *pTblUTCSD = NULL;
	_stPR2000_Reg stReg;
	int regInx = 0;
	uint8_t u8RegData;
	int sizeArray = 0;
	uint8_t *pData = NULL;

	Print("%02x-Set UTC Standard:%d, cameraResolution:%d\n", slvAddr COMMA cameraStandard COMMA cameraResolution);

	if(cameraStandard >= max_camera_standard)
	{
		Error("Invalid standard:%d\n", cameraStandard);
		return(result);
	}
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	if(cameraResolution >= max_camera_resolution)
	{
		Error("Invalid camera resolution:%d\n", cameraResolution);
		return(result);
	}
#else
	if(cameraResolution > camera_1920x1080p25)
	{
		Error("Invalid camera resolution:%d\n", cameraResolution);
		return(result);
	}
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	if(cameraResolution > camera_1920x1080p25)
	{/*{{{*/
		switch(cameraStandard)
		{/*{{{*/
			case SD:
				{
					pTblUTCSD = (const _stPR2000_Table_SD_CameraResolution *)stPR2000_Table_UTC_SD;
				}
				break;
#if defined(SUPPORT_STD_PVI)
			case PVI:
				{
					pTblEXT_UTCHD = (const _stPR2000_Table_EXT_HD_CameraResolution *)stPR2000_Table_EXT_UTC_PVI;
				}
				break;
#endif //defined(SUPPORT_STD_PVI)
#if defined(SUPPORT_STD_HDA)
			case HDA:
				{
					pTblEXT_UTCHD = (const _stPR2000_Table_EXT_HD_CameraResolution *)stPR2000_Table_EXT_UTC_HDA;
				}
				break;
#endif //defined(SUPPORT_STD_HDA)
#if defined(SUPPORT_STD_CVI)
			case CVI:
				{
					pTblEXT_UTCHD = (const _stPR2000_Table_EXT_HD_CameraResolution *)stPR2000_Table_EXT_UTC_CVI;
				}
				break;
#endif //defined(SUPPORT_STD_CVI)
#if defined(SUPPORT_STD_HDT)
			case HDT_OLD:
			case HDT_NEW:
				{
					pTblEXT_UTCHD = (const _stPR2000_Table_EXT_HD_CameraResolution *)stPR2000_Table_EXT_UTC_HDT;
				}
				break;
#endif //defined(SUPPORT_STD_HDT)
			default:
				{
					Error("Invalid camera Standard(%d)\n", cameraStandard);
					return(result);
				}
		}/*}}}*/
	}/*}}}*/
	else
	{/*{{{*/
		switch(cameraStandard)
		{/*{{{*/
			case SD:
				{
					pTblUTCSD = (const _stPR2000_Table_SD_CameraResolution *)stPR2000_Table_UTC_SD;
				}
				break;
#if defined(SUPPORT_STD_PVI)
			case PVI:
				{
					pTblSTD_UTCHD = (const _stPR2000_Table_STD_HD_CameraResolution *)stPR2000_Table_STD_UTC_PVI;
				}
				break;
#endif //defined(SUPPORT_STD_PVI)
#if defined(SUPPORT_STD_HDA)
			case HDA:
				{
					pTblSTD_UTCHD = (const _stPR2000_Table_STD_HD_CameraResolution *)stPR2000_Table_STD_UTC_HDA;
				}
				break;
#endif //defined(SUPPORT_STD_HDA)
#if defined(SUPPORT_STD_CVI)
			case CVI:
				{
					pTblSTD_UTCHD = (const _stPR2000_Table_STD_HD_CameraResolution *)stPR2000_Table_STD_UTC_CVI;
				}
				break;
#endif //defined(SUPPORT_STD_CVI)
#if defined(SUPPORT_STD_HDT)
			case HDT_OLD:
			case HDT_NEW:
				{
					pTblSTD_UTCHD = (const _stPR2000_Table_STD_HD_CameraResolution *)stPR2000_Table_STD_UTC_HDT;
				}
				break;
#endif //defined(SUPPORT_STD_HDT)
			default:
				{
					Error("Invalid camera Standard(%d)\n", cameraStandard);
					return(result);
				}
		}/*}}}*/
	}/*}}}*/
#else
	/* set table */
	switch(cameraStandard)
	{/*{{{*/
		case SD:
			{
				pTblUTCSD = (const _stPR2000_Table_SD_CameraResolution *)stPR2000_Table_UTC_SD;
			}
			break;
#if defined(SUPPORT_STD_PVI)
		case PVI:
			{
				pTblSTD_UTCHD = (const _stPR2000_Table_STD_HD_CameraResolution *)stPR2000_Table_STD_UTC_PVI;
			}
			break;
#endif //defined(SUPPORT_STD_PVI)
#if defined(SUPPORT_STD_HDA)
		case HDA:
			{
				pTblSTD_UTCHD = (const _stPR2000_Table_STD_HD_CameraResolution *)stPR2000_Table_STD_UTC_HDA;
			}
			break;
#endif //defined(SUPPORT_STD_HDA)
#if defined(SUPPORT_STD_CVI)
		case CVI:
			{
				pTblSTD_UTCHD = (const _stPR2000_Table_STD_HD_CameraResolution *)stPR2000_Table_STD_UTC_CVI;
			}
			break;
#endif //defined(SUPPORT_STD_CVI)
#if defined(SUPPORT_STD_HDT)
		case HDT_OLD:
		case HDT_NEW:
			{
				pTblSTD_UTCHD = (const _stPR2000_Table_STD_HD_CameraResolution *)stPR2000_Table_STD_UTC_HDT;
			}
			break;
#endif //defined(SUPPORT_STD_HDT)
		default:
			{
				Error("Invalid camera Standard(%d)\n", cameraStandard);
				return(result);
			}
	}/*}}}*/
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

	if( (cameraStandard == SD) && (pTblUTCSD != NULL) )
	{/*{{{*/
		regInx = 0;
		stReg.reg = pTblUTCSD[regInx].stReg.reg;
		while(stReg.reg != 0xFFFF)
		{
			u8RegData = pTblUTCSD[regInx].u8Data[cameraResolution];
			Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}

			regInx++;
			stReg.reg = pTblUTCSD[regInx].stReg.reg;
		}
	}/*}}}*/
	else
	{
		if( (pTblSTD_UTCHD != NULL) )
		{/*{{{*/
			regInx = 0;
			stReg.reg = pTblSTD_UTCHD[regInx].stReg.reg;
			while(stReg.reg != 0xFFFF)
			{
				u8RegData = pTblSTD_UTCHD[regInx].u8Data[cameraResolution-camera_1280x720p60]; 
				Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}

				regInx++;
				stReg.reg = pTblSTD_UTCHD[regInx].stReg.reg;
			}
		}/*}}}*/
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
		if( (pTblEXT_UTCHD != NULL) )
		{/*{{{*/
			regInx = 0;
			stReg.reg = pTblEXT_UTCHD[regInx].stReg.reg;
			while(stReg.reg != 0xFFFF)
			{
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
				u8RegData = pTblEXT_UTCHD[regInx].u8Data[cameraResolution-camera_1280x800p60]; 
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
				u8RegData = pTblEXT_UTCHD[regInx].u8Data[cameraResolution-camera_1280x960p60]; 
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
				Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}

				regInx++;
				stReg.reg = pTblEXT_UTCHD[regInx].stReg.reg;
			}
		}/*}}}*/
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	}

	/* set pattern */
	switch(cameraStandard)
	{/*{{{*/
		case SD:
			{/*{{{*/
				/* set tx pattern format */
				sizeArray = sizeof(pr2000_ptz_table_sd_tx_pat_format)/sizeof(pr2000_ptz_table_sd_tx_pat_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_sd_tx_pat_format;
				stReg.reg = 0x0210;
				u8RegData = 0x81;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set tx pattern data */
				sizeArray = sizeof(pr2000_ptz_table_sd_tx_pat_data)/sizeof(pr2000_ptz_table_sd_tx_pat_data[0]);
				pData = (uint8_t *)pr2000_ptz_table_sd_tx_pat_data;
				stReg.reg = 0x0210;
				u8RegData = 0x82;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern format */
				sizeArray = sizeof(pr2000_ptz_table_sd_rx_pat_format)/sizeof(pr2000_ptz_table_sd_rx_pat_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_sd_rx_pat_format;
				stReg.reg = 0x0210;
				u8RegData = 0x84;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern start format */
				sizeArray = sizeof(pr2000_ptz_table_sd_rx_pat_start_format)/sizeof(pr2000_ptz_table_sd_rx_pat_start_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_sd_rx_pat_start_format;
				stReg.reg = 0x0210;
				u8RegData = 0x85;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern start data */
				sizeArray = sizeof(pr2000_ptz_table_sd_rx_pat_start_data)/sizeof(pr2000_ptz_table_sd_rx_pat_start_data[0]);
				pData = (uint8_t *)pr2000_ptz_table_sd_rx_pat_start_data;
				stReg.reg = 0x0210;
				u8RegData = 0x86;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}
			}/*}}}*/
			break;
#if defined(SUPPORT_STD_PVI)
		case PVI:
			{/*{{{*/
				/* set tx pattern format */
				sizeArray = sizeof(pr2000_ptz_table_std_pvi_tx_pat_format)/sizeof(pr2000_ptz_table_std_pvi_tx_pat_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_pvi_tx_pat_format;
				stReg.reg = 0x0210;
				u8RegData = 0x81;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set tx pattern data */
				sizeArray = sizeof(pr2000_ptz_table_std_pvi_tx_pat_data)/sizeof(pr2000_ptz_table_std_pvi_tx_pat_data[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_pvi_tx_pat_data;
				stReg.reg = 0x0210;
				u8RegData = 0x82;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern format */
				sizeArray = sizeof(pr2000_ptz_table_std_pvi_rx_pat_format)/sizeof(pr2000_ptz_table_std_pvi_rx_pat_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_pvi_rx_pat_format;
				stReg.reg = 0x0210;
				u8RegData = 0x84;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern start format */
				sizeArray = sizeof(pr2000_ptz_table_std_pvi_rx_pat_start_format)/sizeof(pr2000_ptz_table_std_pvi_rx_pat_start_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_pvi_rx_pat_start_format;
				stReg.reg = 0x0210;
				u8RegData = 0x85;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern start data */
				sizeArray = sizeof(pr2000_ptz_table_std_pvi_rx_pat_start_data)/sizeof(pr2000_ptz_table_std_pvi_rx_pat_start_data[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_pvi_rx_pat_start_data;
				stReg.reg = 0x0210;
				u8RegData = 0x86;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_PVI)
#if defined(SUPPORT_STD_HDA)
		case HDA:
			{
				if(cameraResolution >= camera_1920x1080p30)
				{/*{{{*/
					/* set tx pattern format */
					sizeArray = sizeof(pr2000_ptz_table_std_hda_tx_pat_format_1080p)/sizeof(pr2000_ptz_table_std_hda_tx_pat_format_1080p[0]);
					pData = (uint8_t *)pr2000_ptz_table_std_hda_tx_pat_format_1080p;
					stReg.reg = 0x0210;
					u8RegData = 0x81;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
					{
						ErrorString("invalid fifo count\n");
						return(result);
					}

					/* set tx pattern data */
					sizeArray = sizeof(pr2000_ptz_table_std_hda_tx_pat_data_1080p)/sizeof(pr2000_ptz_table_std_hda_tx_pat_data_1080p[0]);
					pData = (uint8_t *)pr2000_ptz_table_std_hda_tx_pat_data_1080p;
					stReg.reg = 0x0210;
					u8RegData = 0x82;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
					{
						ErrorString("invalid fifo count\n");
						return(result);
					}

					/* set rx pattern format */
					sizeArray = sizeof(pr2000_ptz_table_std_hda_rx_pat_format_1080p)/sizeof(pr2000_ptz_table_std_hda_rx_pat_format_1080p[0]);
					pData = (uint8_t *)pr2000_ptz_table_std_hda_rx_pat_format_1080p;
					stReg.reg = 0x0210;
					u8RegData = 0x84;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
					{
						ErrorString("invalid fifo count\n");
						return(result);
					}


					/* set rx pattern start format */
					sizeArray = sizeof(pr2000_ptz_table_std_hda_rx_pat_start_format_1080p)/sizeof(pr2000_ptz_table_std_hda_rx_pat_start_format_1080p[0]);
					pData = (uint8_t *)pr2000_ptz_table_std_hda_rx_pat_start_format_1080p;
					stReg.reg = 0x0210;
					u8RegData = 0x85;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
					{
						ErrorString("invalid fifo count\n");
						return(result);
					}

					/* set rx pattern start data */
					sizeArray = sizeof(pr2000_ptz_table_std_hda_rx_pat_start_data_1080p)/sizeof(pr2000_ptz_table_std_hda_rx_pat_start_data_1080p[0]);
					pData = (uint8_t *)pr2000_ptz_table_std_hda_rx_pat_start_data_1080p;
					stReg.reg = 0x0210;
					u8RegData = 0x86;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
					{
						ErrorString("invalid fifo count\n");
						return(result);
					}
				}/*}}}*/
				else
				{/*{{{*/
					/* set tx pattern format */
					sizeArray = sizeof(pr2000_ptz_table_std_hda_tx_pat_format_720p)/sizeof(pr2000_ptz_table_std_hda_tx_pat_format_720p[0]);
					pData = (uint8_t *)pr2000_ptz_table_std_hda_tx_pat_format_720p;
					stReg.reg = 0x0210;
					u8RegData = 0x81;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
					{
						ErrorString("invalid fifo count\n");
						return(result);
					}

					/* set tx pattern data */
					sizeArray = sizeof(pr2000_ptz_table_std_hda_tx_pat_data_720p)/sizeof(pr2000_ptz_table_std_hda_tx_pat_data_720p[0]);
					pData = (uint8_t *)pr2000_ptz_table_std_hda_tx_pat_data_720p;
					stReg.reg = 0x0210;
					u8RegData = 0x82;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
					{
						ErrorString("invalid fifo count\n");
						return(result);
					}

					/* set rx pattern format */
					sizeArray = sizeof(pr2000_ptz_table_std_hda_rx_pat_format_720p)/sizeof(pr2000_ptz_table_std_hda_rx_pat_format_720p[0]);
					pData = (uint8_t *)pr2000_ptz_table_std_hda_rx_pat_format_720p;
					stReg.reg = 0x0210;
					u8RegData = 0x84;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
					{
						ErrorString("invalid fifo count\n");
						return(result);
					}

					/* set rx pattern start format */
					sizeArray = sizeof(pr2000_ptz_table_std_hda_rx_pat_start_format_720p)/sizeof(pr2000_ptz_table_std_hda_rx_pat_start_format_720p[0]);
					pData = (uint8_t *)pr2000_ptz_table_std_hda_rx_pat_start_format_720p;
					stReg.reg = 0x0210;
					u8RegData = 0x85;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
					{
						ErrorString("invalid fifo count\n");
						return(result);
					}

					/* set rx pattern start data */
					sizeArray = sizeof(pr2000_ptz_table_std_hda_rx_pat_start_data_720p)/sizeof(pr2000_ptz_table_std_hda_rx_pat_start_data_720p[0]);
					pData = (uint8_t *)pr2000_ptz_table_std_hda_rx_pat_start_data_720p;
					stReg.reg = 0x0210;
					u8RegData = 0x86;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
					if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
					{
						ErrorString("invalid fifo count\n");
						return(result);
					}
				}/*}}}*/
			}
			break;
#endif //defined(SUPPORT_STD_HDA)
#if defined(SUPPORT_STD_CVI)
		case CVI:
			{/*{{{*/
				/* set tx pattern format */
				sizeArray = sizeof(pr2000_ptz_table_std_cvi_tx_pat_format)/sizeof(pr2000_ptz_table_std_cvi_tx_pat_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_cvi_tx_pat_format;
				stReg.reg = 0x0210;
				u8RegData = 0x81;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set tx pattern data */
				sizeArray = sizeof(pr2000_ptz_table_std_cvi_tx_pat_data)/sizeof(pr2000_ptz_table_std_cvi_tx_pat_data[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_cvi_tx_pat_data;
				stReg.reg = 0x0210;
				u8RegData = 0x82;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern format */
				sizeArray = sizeof(pr2000_ptz_table_std_cvi_rx_pat_format)/sizeof(pr2000_ptz_table_std_cvi_rx_pat_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_cvi_rx_pat_format;
				stReg.reg = 0x0210;
				u8RegData = 0x84;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern start format */
				sizeArray = sizeof(pr2000_ptz_table_std_cvi_rx_pat_start_format)/sizeof(pr2000_ptz_table_std_cvi_rx_pat_start_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_cvi_rx_pat_start_format;
				stReg.reg = 0x0210;
				u8RegData = 0x85;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern start data */
				sizeArray = sizeof(pr2000_ptz_table_std_cvi_rx_pat_start_data)/sizeof(pr2000_ptz_table_std_cvi_rx_pat_start_data[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_cvi_rx_pat_start_data;
				stReg.reg = 0x0210;
				u8RegData = 0x86;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_CVI)
#if defined(SUPPORT_STD_HDT)
		case HDT_OLD:
		case HDT_NEW:
			{/*{{{*/
				/* set tx pattern format */
				sizeArray = sizeof(pr2000_ptz_table_std_hdt_tx_pat_format)/sizeof(pr2000_ptz_table_std_hdt_tx_pat_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_hdt_tx_pat_format;
				stReg.reg = 0x0210;
				u8RegData = 0x81;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set tx pattern data */
				sizeArray = sizeof(pr2000_ptz_table_std_hdt_tx_pat_data)/sizeof(pr2000_ptz_table_std_hdt_tx_pat_data[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_hdt_tx_pat_data;
				stReg.reg = 0x0210;
				u8RegData = 0x82;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern format */
				sizeArray = sizeof(pr2000_ptz_table_std_hdt_rx_pat_format)/sizeof(pr2000_ptz_table_std_hdt_rx_pat_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_hdt_rx_pat_format;
				stReg.reg = 0x0210;
				u8RegData = 0x84;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern start format */
				sizeArray = sizeof(pr2000_ptz_table_std_hdt_rx_pat_start_format)/sizeof(pr2000_ptz_table_std_hdt_rx_pat_start_format[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_hdt_rx_pat_start_format;
				stReg.reg = 0x0210;
				u8RegData = 0x85;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}

				/* set rx pattern start data */
				sizeArray = sizeof(pr2000_ptz_table_std_hdt_rx_pat_start_data)/sizeof(pr2000_ptz_table_std_hdt_rx_pat_start_data[0]);
				pData = (uint8_t *)pr2000_ptz_table_std_hdt_rx_pat_start_data;
				stReg.reg = 0x0210;
				u8RegData = 0x86;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
				if( (result = PR2000_UTC_WriteFlagFifo(i2cFd, slvAddr, sizeArray, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_HDT)
		default:
			{
				Error("Invalid camera Standard(%d)\n", cameraStandard);
				return(result);
			}
	}/*}}}*/

	/* set rx fifo configuration. do last */
	switch(cameraStandard)
	{/*{{{*/
		case SD:
			{/*{{{*/
				stReg.reg = 0x0214;
				u8RegData = 0x93;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
			break;
#if defined(SUPPORT_STD_PVI)
		case PVI:
			{/*{{{*/
				stReg.reg = 0x0214;
				u8RegData = 0x93;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_PVI)
#if defined(SUPPORT_STD_HDA)
		case HDA:
			{
				if(cameraResolution >= camera_1920x1080p30)
				{/*{{{*/
					stReg.reg = 0x0214;
					u8RegData = 0x93;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}/*}}}*/
				else
				{/*{{{*/
					stReg.reg = 0x0214;
					u8RegData = 0xD3;
					if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}/*}}}*/
			}
			break;
#endif //defined(SUPPORT_STD_HDA)
#if defined(SUPPORT_STD_CVI)
		case CVI:
			{/*{{{*/
				stReg.reg = 0x0214;
				u8RegData = 0xD3;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_CVI)
#if defined(SUPPORT_STD_HDT)
		case HDT_OLD:
		case HDT_NEW:
			{/*{{{*/
				stReg.reg = 0x0214;
				u8RegData = 0x93;
				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_HDT)
		default:
			{
				Error("Invalid camera Standard(%d)\n", cameraStandard);
				return(result);
			}
	}/*}}}*/

	return(result);
}

int PR2000_UTC_StartRX(const int i2cFd, const uint8_t slvAddr, const int bStart)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;
	uint8_t u8RegMask;

	if(bStart)
	{
		DbgString("Start UTC_RX\n");
		stReg.reg = 0x0200;
		u8RegMask = 0xC0; u8RegData = 0xC0;
		if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
		{
			ErrorString("Write reg.\n");
			return(-1);
		}

		stReg.reg = 0x0214;
		u8RegMask = 0x97; u8RegData = 0x83;
		if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
		{
			ErrorString("Write reg.\n");
			return(-1);
		}
	}
	else
	{
		DbgString("Stop UTC_RX\n");
		stReg.reg = 0x0200;
		u8RegMask = 0x40; u8RegData = 0x00;
		if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
		{
			ErrorString("Write reg.\n");
			return(-1);
		}
	}
	return(result);
}

int PR2000_UTC_StartTX(const int i2cFd, const uint8_t slvAddr, const int bStart)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;
	uint8_t u8RegMask;

	if(bStart)
	{
		DbgString("Start UTC_TX\n");
		u8RegMask = 0x40; u8RegData = 0x40;
	}
	else
	{
		DbgString("Stop UTC_TX\n");
		u8RegMask = 0x40; u8RegData = 0x00;
	} 
	stReg.reg = 0x0220;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("Write reg..\n");
		return(-1);
	}

	return(result);
}


int PR2000_UTC_SendData(const int i2cFd, const uint8_t slvAddr, const enum _eCameraStandard cameraStandard, const enum _eCameraResolution cameraResolution, const int dataSize, const uint8_t *pData)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegMask;
	uint8_t u8RegData = 0;

	Print("%02x-Send Standard:%d, cameraResolution:%d\n", slvAddr COMMA cameraStandard COMMA cameraResolution);

	if(cameraStandard >= max_camera_standard)
	{
		Error("Invalid standard:%d\n", cameraStandard);
		return(result);
	}
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	if(cameraResolution >= max_camera_resolution)
	{
		Error("Invalid camera resolution:%d\n", cameraResolution);
		return(result);
	}
#else
	if(cameraResolution > camera_1920x1080p25)
	{
		Error("Invalid camera resolution:%d\n", cameraResolution);
		return(result);
	}
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

	if( (dataSize <= 0) || (pData == NULL) )
	{
		ErrorString("Invalid utc data\n");
		return(result);
	}

	/* check current tx fifo size */
	stReg.reg = 0x0212;
	result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
	if(u8RegData != 0)
	{
		ErrorString("Not empty\n");
		return(result);
	}

	/* send utc data */
	switch(cameraStandard)
	{/*{{{*/
		case SD:
			{/*{{{*/
				/* init data reg */
				stReg.reg = 0x0210;
				u8RegMask = 0xC7;
				u8RegData = 0x00;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}

				/* write utc data */
				if( (result = PR2000_UTC_SendTxFifo(i2cFd, slvAddr, cameraStandard, cameraResolution, dataSize, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}
			}/*}}}*/
			break;
#if defined(SUPPORT_STD_PVI)
		case PVI:
			{/*{{{*/
				/* init data reg */
				stReg.reg = 0x0210;
				u8RegMask = 0xC7;
				u8RegData = 0x00;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}

				/* write utc data */
				if( (result = PR2000_UTC_SendTxFifo(i2cFd, slvAddr, cameraStandard, cameraResolution, dataSize, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_PVI)
#if defined(SUPPORT_STD_HDA)
		case HDA:
			{/*{{{*/
				/* init data reg */
				if(cameraResolution >= camera_1920x1080p30)
				{/*{{{*/
					stReg.reg = 0x0210;
					u8RegMask = 0xC7;
					u8RegData = 0x00;
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}/*}}}*/
				else
				{/*{{{*/
					stReg.reg = 0x0210;
					u8RegMask = 0xC7;
					u8RegData = 0x40;
					if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
					{
						ErrorString("invalid page write\n");
						return(result);
					}
				}/*}}}*/

				/* write utc data */
				if( (result = PR2000_UTC_SendTxFifo(i2cFd, slvAddr, cameraStandard, cameraResolution, dataSize, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_HDA)
#if defined(SUPPORT_STD_CVI)
		case CVI:
			{/*{{{*/
				/* init data reg */
				stReg.reg = 0x0210;
				u8RegMask = 0xC7;
				u8RegData = 0x40;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}

				/* write utc data */
				if( (result = PR2000_UTC_SendTxFifo(i2cFd, slvAddr, cameraStandard, cameraResolution, dataSize, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_CVI)
#if defined(SUPPORT_STD_HDT)
		case HDT_OLD:
		case HDT_NEW:
			{/*{{{*/
				/* init data reg */
				stReg.reg = 0x0210;
				u8RegMask = 0xC7;
				u8RegData = 0x00;
				if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}

				/* write utc data */
				if( (result = PR2000_UTC_SendTxFifo(i2cFd, slvAddr, cameraStandard, cameraResolution, dataSize, pData)) < 0)
				{
					ErrorString("invalid fifo count\n");
					return(result);
				}
			}/*}}}*/
			break;
#endif //defined(SUPPORT_STD_HDT)
		default:
			{
				Error("Invalid camera Standard(%d)\n", cameraStandard);
				return(result);
			}
	}/*}}}*/

	return(result);
}

int PR2000_UTC_GetRxAttr(const int i2cFd, const uint8_t slvAddr, _stUTCRxAttr *pstUTCRxAttr)
{
	int result = -1;

	_stPR2000_Reg stReg;

	if(pstUTCRxAttr == NULL)
	{
		ErrorString("Invalid argu\n");
		return(-1);
	}

	stReg.reg = 0x0200;
	DbgString("UTC GetRxRegs\n");
	if( (result = PR2000_PageReadBurst(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, sizeof(_stUTCRxAttr), (uint8_t *)pstUTCRxAttr)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}

	return(result);
}

int PR2000_UTC_GetTxAttr(const int i2cFd, const uint8_t slvAddr, _stUTCTxAttr *pstUTCTxAttr)
{
	int result = -1;

	_stPR2000_Reg stReg;

	if(pstUTCTxAttr == NULL)
	{
		ErrorString("Invalid argu\n");
		return(-1);
	}

	stReg.reg = 0x0220;
	DbgString("PTZ GetTxRegs\n");
	if( (result = PR2000_PageReadBurst(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, sizeof(_stUTCTxAttr), (uint8_t *)pstUTCTxAttr)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}

	return(result);
}

int PR2000_UTC_GetHVStartAttr(const int i2cFd, const uint8_t slvAddr, _stUTCHVStartAttr *pstUTCHVStartAttr)
{
	int result = -1;

	_stPR2000_Reg stReg;

	if(pstUTCHVStartAttr == NULL)
	{
		ErrorString("Invalid argu\n");
		return(-1);
	}

	stReg.reg = 0x0218;
	DbgString("PTZ GetHVStartRegs\n");
	if( (result = PR2000_PageReadBurst(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, sizeof(_stUTCHVStartAttr), (uint8_t *)pstUTCHVStartAttr)) < 0)
	{
		ErrorString("Read reg.\n");
		return(-1);
	}

	return(result);
}


#endif //SUPPORT_UTC

#ifdef SUPPORT_OSG
int PR2000_OSG_WriteSPI(const int i2cFd, const uint8_t slvAddr, const uint32_t addr, const uint32_t dataSize, const uint8_t *pData)
{
	int result = -1;
	_stPR2000_Reg stReg;
	int maxFifoPage = 0, fifoPageCnt = 0, remainSize = 0;
	uint8_t u8RegMask;
	uint8_t u8RegData;
	int i;
	uint32_t spiAddr = 0;
	const uint32_t burstSize = 256;
	int retryCnt = 0;

	if( (dataSize == 0) || (pData == NULL) )
	{
		ErrorString("Invalid argument\n");
		return(result);
	}

	Print("%02x-osg write spi. addr:0x%08x, size:0x%02x, pdata[0]:0x%02x\n", slvAddr COMMA addr COMMA dataSize COMMA pData[0]);

	/* osg path disable */
	stReg.reg = 0x0280;
	u8RegMask = 0x80;
	u8RegData = 0x00;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// Path_en + Edge Sel + Divider = 1
	stReg.reg = 0x0240;
	u8RegMask = 0x80;
	u8RegData = 0x80;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	maxFifoPage = dataSize/burstSize;

	for(fifoPageCnt = 0; fifoPageCnt < maxFifoPage; fifoPageCnt++)
	{/*{{{*/
		//  addr_wr_lat = 1, wr_hold, wr_md,  page = 0
		stReg.reg = 0x0250;
		u8RegData = 0xE0;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// Fifo Addr = 0
		stReg.reg = 0x0251;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// 256 Data Dump.
		for(i = 0; i < burstSize; i++)
		{
			stReg.reg = 0x0252;
			u8RegData = pData[i+(fifoPageCnt*burstSize)];
			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}
		}
		//** test_spi Buffer Write Done...   **

		//** test_spi WREN start...   **
		// cmd = 06 for WREN (write)
		stReg.reg = 0x0241;
		u8RegData = 0x06;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		
		// write + host_spi_data_size = 0 Ea
		stReg.reg = 0x0246;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		stReg.reg = 0x0247;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// cmd type = 1 cmd
		stReg.reg = 0x0248;
		u8RegData = 0x01;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// spi_req, page = 0
		stReg.reg = 0x0249;
		u8RegData = 0x80;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);
		//** test_spi WREN Done...   **

		//** Multi SPI MEM Write Request Start...   **
		// cmd = 02 for PP (write)
		stReg.reg = 0x0241;
		u8RegData = 0x02;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		spiAddr = addr + (fifoPageCnt*burstSize);
		Dbg("spiAddr:0x%08x, size:%d\n", spiAddr COMMA burstSize);
		// addr2
		stReg.reg = 0x0242;
		u8RegData = (spiAddr>>16)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr1
		stReg.reg = 0x0243;
		u8RegData = (spiAddr>>8)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr0
		stReg.reg = 0x0244;
		u8RegData = (spiAddr)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// dummy cmd4
		stReg.reg = 0x0245;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// write + host_spi_data_size = 64 Ea
		stReg.reg = 0x0246;
		u8RegData = 0x80 + ((burstSize>>8)&0x1);
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// burst_size
		stReg.reg = 0x0247;
		u8RegData = (burstSize)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// cmd type = 4 cmd + Max 256 Write
		stReg.reg = 0x0248;
		u8RegData = 0x04;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// spi_req, PH
		stReg.reg = 0x0249;
		u8RegData = 0x80 + 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Period Check..
		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);

		//** Multi SPI MEM Write Request Done...   **
		// cmd = 05 for RDSR (Status Read)
		stReg.reg = 0x0241;
		u8RegData = 0x05;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// single_rx[7] + host_spi_data_size = 1 Ea
		stReg.reg = 0x0246;
		u8RegData = 0x80;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		stReg.reg = 0x0247;
		u8RegData = 0x01;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// rw_mode[7] + cmd type = 1 cmd + 1 read
		stReg.reg = 0x0248;
		u8RegData = 0x81;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Status Check..
		do
		{
			// Status Read Request
			stReg.reg = 0x0249;
			u8RegData = 0x80;
			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}

			// SPI Write Period Check..
			retryCnt = 0;
			do
			{
				stReg.reg = 0x0249;
				u8RegData = 0;
				result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
				msleep(1);
				if(retryCnt++ > 100) return(-1);
				Dbg("u8RegData:0x%02x\n", u8RegData);
			} while(u8RegData & 0x80);

			// Status Data Check
			stReg.reg = 0x024A;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
		} while(u8RegData & 0x01);
		//**Multi test_spi MEM Write Done...   **
	}/*}}}*/

	remainSize = dataSize%burstSize;
	if(remainSize > 0)
	{/*{{{*/
		//  addr_wr_lat = 1, wr_hold, wr_md,  page = 0
		stReg.reg = 0x0250;
		u8RegData = 0xE0;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// Fifo Addr = 0
		stReg.reg = 0x0251;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// Data Dump.
		for(i = 0; i < remainSize; i++)
		{
			stReg.reg = 0x0252;
			u8RegData = pData[i+(maxFifoPage*burstSize)];
			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}
		}
		//** test_spi Buffer Write Done...   **

		//** test_spi WREN start...   **
		// cmd = 06 for WREN (write)
		stReg.reg = 0x0241;
		u8RegData = 0x06;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		
		// write + host_spi_data_size = 0 Ea
		stReg.reg = 0x0246;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		stReg.reg = 0x0247;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// cmd type = 1 cmd
		stReg.reg = 0x0248;
		u8RegData = 0x01;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// spi_req, page = 0
		stReg.reg = 0x0249;
		u8RegData = 0x80;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);
		//** test_spi WREN Done...   **

		//** Multi SPI MEM Write Request Start...   **
		// cmd = 02 for PP (write)
		stReg.reg = 0x0241;
		u8RegData = 0x02;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		spiAddr = addr + (maxFifoPage*burstSize);
		Dbg("spiAddr:0x%08x, remain size:%d\n", spiAddr COMMA remainSize);
		// addr2
		stReg.reg = 0x0242;
		u8RegData = (spiAddr>>16)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr1
		stReg.reg = 0x0243;
		u8RegData = (spiAddr>>8)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr0
		stReg.reg = 0x0244;
		u8RegData = (spiAddr)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// dummy cmd4
		stReg.reg = 0x0245;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// write + host_spi_data_size = 64 Ea
		stReg.reg = 0x0246;
		u8RegData = 0x80 + ((remainSize>>8)&0x1);
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// burst_size
		stReg.reg = 0x0247;
		u8RegData = (remainSize)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// cmd type = 4 cmd + Max 256 Write
		stReg.reg = 0x0248;
		u8RegData = 0x04;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// spi_req, PH
		stReg.reg = 0x0249;
		u8RegData = 0x80 + 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Period Check..
		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);

		//** Multi SPI MEM Write Request Done...   **
		// cmd = 05 for RDSR (Status Read)
		stReg.reg = 0x0241;
		u8RegData = 0x05;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// single_rx[7] + host_spi_data_size = 1 Ea
		stReg.reg = 0x0246;
		u8RegData = 0x80;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		stReg.reg = 0x0247;
		u8RegData = 0x01;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// rw_mode[7] + cmd type = 1 cmd + 1 read
		stReg.reg = 0x0248;
		u8RegData = 0x81;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Status Check..
		do
		{
			// Status Read Request
			stReg.reg = 0x0249;
			u8RegData = 0x80;
			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}

			// SPI Write Period Check..
			retryCnt = 0;
			do
			{
				stReg.reg = 0x0249;
				u8RegData = 0;
				result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
				msleep(1);
				if(retryCnt++ > 100) return(-1);
				Dbg("u8RegData:0x%02x\n", u8RegData);
			} while(u8RegData & 0x80);

			// Status Data Check
			stReg.reg = 0x024A;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
		} while(u8RegData & 0x01);
		//**Multi test_spi MEM Write Done...   **
	}/*}}}*/

	// Path_en + Edge Sel + Divider = 0
#if 0
	stReg.reg = 0x0240;
	u8RegMask = 0x80;
	u8RegData = 0x00;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
#endif
	return(result);
}

int PR2000_OSG_ReadSPI(const int i2cFd, const uint8_t slvAddr, const uint32_t addr, const uint32_t dataSize, uint8_t *pData)
{
	int result = -1;
	_stPR2000_Reg stReg;
	int maxFifoPage = 0, fifoPageCnt = 0, remainSize = 0;
	uint8_t u8RegMask;
	uint8_t u8RegData;
	int i;
	uint32_t spiAddr = 0;
	const uint32_t burstSize = 256;
	int retryCnt = 0;

	if( (dataSize == 0) || (pData == NULL) )
	{
		ErrorString("Invalid argument\n");
		return(result);
	}

	Print("%02x-osg read single spi. addr:0x%08x, size:0x%02x\n", slvAddr COMMA addr COMMA dataSize);

	/* osg path disable */
	stReg.reg = 0x0280;
	u8RegMask = 0x80;
	u8RegData = 0x00;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	/* osg path disable update */
	stReg.reg = 0x0293;
	u8RegMask = 0x81;
	u8RegData = 0x81;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}


	// Path_en + Edge Sel + Divider = 1
	stReg.reg = 0x0240;
	u8RegMask = 0x80;
	u8RegData = 0x80;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	//** test_spi Single Read start...   **
	// cmd = 03 for SRD (Read)
	stReg.reg = 0x0241;
	u8RegData = 0x03;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// dummy cmd4
	stReg.reg = 0x0245;
	u8RegData = 0x00;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// host_spi_data_size = 64 Ea
	stReg.reg = 0x0246;
	u8RegData = (burstSize>>8)&0x1;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	stReg.reg = 0x0247;
	u8RegData = burstSize&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// rx_type(1) + cmd type = 4 cmd
	stReg.reg = 0x0248;
	u8RegData = 0x84;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	//** test_spi MEM Read Start...   **
	maxFifoPage = dataSize/burstSize;

	for(fifoPageCnt = 0; fifoPageCnt < maxFifoPage; fifoPageCnt++)
	{/*{{{*/
		spiAddr = addr + (fifoPageCnt*burstSize);
		Dbg("spiAddr:0x%08x, size:%d\n", spiAddr COMMA burstSize);
		// addr2
		stReg.reg = 0x0242;
		u8RegData = (spiAddr>>16)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr1
		stReg.reg = 0x0243;
		u8RegData = (spiAddr>>8)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr0
		stReg.reg = 0x0244;
		u8RegData = (spiAddr)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// spi_req, PH
		stReg.reg = 0x0249;
		u8RegData = 0x80 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Period Check..
		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);

		// addr_rd_hold = 1, page = 0
		stReg.reg = 0x0258;
		u8RegData = 0x40 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// Fifo Addr = 0
		stReg.reg = 0x0259;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// Data Dump.
		for(i = 0; i < burstSize; i++)
		{
			stReg.reg = 0x025A;
			if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
			{
				ErrorString("invalid read\n");
				return(result);
			}
			pData[i+(fifoPageCnt*burstSize)] = u8RegData;
		}
		//** test_spi FIFO Read Done...   **
	}/*}}}*/

	remainSize = dataSize%burstSize;
	if(remainSize > 0)
	{/*{{{*/
		spiAddr = addr + (maxFifoPage*burstSize);
		Dbg("spiAddr:0x%08x, remain size:%d\n", spiAddr COMMA remainSize);
		// addr2
		stReg.reg = 0x0242;
		u8RegData = (spiAddr>>16)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr1
		stReg.reg = 0x0243;
		u8RegData = (spiAddr>>8)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr0
		stReg.reg = 0x0244;
		u8RegData = (spiAddr)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// spi_req, PH
		stReg.reg = 0x0249;
		u8RegData = 0x80 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Period Check..
		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);

		// addr_rd_hold = 1, page = 0
		stReg.reg = 0x0258;
		u8RegData = 0x40 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// Fifo Addr = 0
		stReg.reg = 0x0259;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// Data Dump.
		for(i = 0; i < remainSize; i++)
		{
			stReg.reg = 0x025A;
			if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
			{
				ErrorString("invalid read\n");
				return(result);
			}
			pData[i+(maxFifoPage*burstSize)] = u8RegData;
		}
		//** test_spi FIFO Read Done...   **
	}/*}}}*/
#if 0
	// Path_en + Edge Sel + Divider = 1
	stReg.reg = 0x0240;
	u8RegMask = 0x80;
	u8RegData = 0x00;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
#endif
	return(result);
}

int PR2000_OSG_ReadSPIFastDual(const int i2cFd, const uint8_t slvAddr, const uint32_t addr, const uint32_t dataSize, uint8_t *pData)
{
	int result = -1;
	_stPR2000_Reg stReg;
	int maxFifoPage = 0, fifoPageCnt = 0, remainSize = 0;
	uint8_t u8RegMask;
	uint8_t u8RegData;
	int i;
	uint32_t spiAddr = 0;
	const uint32_t burstSize = 256;
	int retryCnt = 0;

	if( (dataSize == 0) || (pData == NULL) )
	{
		ErrorString("Invalid argument\n");
		return(result);
	}

	Print("%02x-osg read fastdual spi. addr:0x%08x, size:0x%02x\n", slvAddr COMMA addr COMMA dataSize);

	/* osg path disable */
	stReg.reg = 0x0280;
	u8RegMask = 0x80;
	u8RegData = 0x00;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// Path_en + Edge Sel + Divider = 1
	stReg.reg = 0x0240;
	u8RegMask = 0x80;
	u8RegData = 0x80;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	//** test_spi Fast Dual Read start...   **
	
	// cmd = 3B for Fast Read Dual I/O (Read)
	stReg.reg = 0x0241;
	u8RegData = 0x3B;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// dummy cmd4
	stReg.reg = 0x0245;
	u8RegData = 0x00;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// host_spi_data_size = 64 Ea
	stReg.reg = 0x0246;
	u8RegData = (burstSize>>8)&0x1;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	stReg.reg = 0x0247;
	u8RegData = burstSize&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// rx_type(1) + dual addr/data + cmd type = 5 cmd
	stReg.reg = 0x0248;
	u8RegData = 0x95;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	//** test_spi MEM Read Start...   **
	maxFifoPage = dataSize/burstSize;

	for(fifoPageCnt = 0; fifoPageCnt < maxFifoPage; fifoPageCnt++)
	{/*{{{*/
		spiAddr = addr + (fifoPageCnt*burstSize);
		Dbg("spiAddr:0x%08x, size:%d\n", spiAddr COMMA burstSize);
		// addr2
		stReg.reg = 0x0242;
		u8RegData = (spiAddr>>16)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr1
		stReg.reg = 0x0243;
		u8RegData = (spiAddr>>8)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr0
		stReg.reg = 0x0244;
		u8RegData = (spiAddr)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// spi_req, PH
		stReg.reg = 0x0249;
		u8RegData = 0x80 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Period Check..
		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);

		// addr_rd_hold = 1, page = 0
		stReg.reg = 0x0258;
		u8RegData = 0x40 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// Fifo Addr = 0
		stReg.reg = 0x0259;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// Data Dump.
		for(i = 0; i < burstSize; i++)
		{
			stReg.reg = 0x025A;
			if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
			{
				ErrorString("invalid read\n");
				return(result);
			}
			pData[i+(fifoPageCnt*burstSize)] = u8RegData;
		}
		//** test_spi FIFO Read Done...   **
	}/*}}}*/

	remainSize = dataSize%burstSize;
	if(remainSize > 0)
	{/*{{{*/
		spiAddr = addr + (maxFifoPage*burstSize);
		Dbg("spiAddr:0x%08x, remain size:%d\n", spiAddr COMMA remainSize);
		// addr2
		stReg.reg = 0x0242;
		u8RegData = (spiAddr>>16)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr1
		stReg.reg = 0x0243;
		u8RegData = (spiAddr>>8)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr0
		stReg.reg = 0x0244;
		u8RegData = (spiAddr)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// spi_req, PH
		stReg.reg = 0x0249;
		u8RegData = 0x80 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Period Check..
		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);

		// addr_rd_hold = 1, page = 0
		stReg.reg = 0x0258;
		u8RegData = 0x40 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// Fifo Addr = 0
		stReg.reg = 0x0259;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// Data Dump.
		for(i = 0; i < remainSize; i++)
		{
			stReg.reg = 0x025A;
			if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
			{
				ErrorString("invalid read\n");
				return(result);
			}
			pData[i+(maxFifoPage*burstSize)] = u8RegData;
		}
		//** test_spi FIFO Read Done...   **
	}/*}}}*/
#if 0
	// Path_en + Edge Sel + Divider = 0
	stReg.reg = 0x0240;
	u8RegMask = 0x80;
	u8RegData = 0x00;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
#endif
	return(result);
}

int PR2000_OSG_ReadSPIFastDualIO(const int i2cFd, const uint8_t slvAddr, const uint32_t addr, const uint32_t dataSize, uint8_t *pData)
{
	int result = -1;
	_stPR2000_Reg stReg;
	int maxFifoPage = 0, fifoPageCnt = 0, remainSize = 0;
	uint8_t u8RegMask;
	uint8_t u8RegData;
	int i;
	uint32_t spiAddr = 0;
	const uint32_t burstSize = 256;
	int retryCnt = 0;

	if( (dataSize == 0) || (pData == NULL) )
	{
		ErrorString("Invalid argument\n");
		return(result);
	}

	Print("%02x-osg read fastdual IO spi. addr:0x%08x, size:0x%02x\n", slvAddr COMMA addr COMMA dataSize);

	/* osg path disable */
	stReg.reg = 0x0280;
	u8RegMask = 0x80;
	u8RegData = 0x00;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// Path_en + Edge Sel + Divider = 1
	stReg.reg = 0x0240;
	u8RegMask = 0x80;
	u8RegData = 0x80;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	//** test_spi Fast Dual Read start...   **
	
	// cmd = 3B for Fast Read Dual I/O (Read)
	stReg.reg = 0x0241;
	u8RegData = 0xBB;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// dummy cmd4 = Ax or 0F
	stReg.reg = 0x0245;
	u8RegData = 0x0F;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// host_spi_data_size = 64 Ea
	stReg.reg = 0x0246;
	u8RegData = (burstSize>>8)&0x1;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	stReg.reg = 0x0247;
	u8RegData = burstSize&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// rx_type(1) + dual addr/data + cmd type = 4 cmd
	stReg.reg = 0x0248;
	u8RegData = 0xB5;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	//** test_spi MEM Read Start...   **
	maxFifoPage = dataSize/burstSize;

	for(fifoPageCnt = 0; fifoPageCnt < maxFifoPage; fifoPageCnt++)
	{/*{{{*/
		spiAddr = addr + (fifoPageCnt*burstSize);
		Dbg("spiAddr:0x%08x, size:%d\n", spiAddr COMMA burstSize);
		// addr2
		stReg.reg = 0x0242;
		u8RegData = (spiAddr>>16)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr1
		stReg.reg = 0x0243;
		u8RegData = (spiAddr>>8)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr0
		stReg.reg = 0x0244;
		u8RegData = (spiAddr)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// spi_req, PH
		stReg.reg = 0x0249;
		u8RegData = 0x80 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Period Check..
		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);

		// addr_rd_hold = 1, page = 0
		stReg.reg = 0x0258;
		u8RegData = 0x40 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// Fifo Addr = 0
		stReg.reg = 0x0259;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// Data Dump.
		for(i = 0; i < burstSize; i++)
		{
			stReg.reg = 0x025A;
			if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
			{
				ErrorString("invalid read\n");
				return(result);
			}
			pData[i+(fifoPageCnt*burstSize)] = u8RegData;
		}
		//** test_spi FIFO Read Done...   **
	}/*}}}*/

	remainSize = dataSize%burstSize;
	if(remainSize > 0)
	{/*{{{*/
		spiAddr = addr + (maxFifoPage*burstSize);
		Dbg("spiAddr:0x%08x, remain size:%d\n", spiAddr COMMA remainSize);
		// addr2
		stReg.reg = 0x0242;
		u8RegData = (spiAddr>>16)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr1
		stReg.reg = 0x0243;
		u8RegData = (spiAddr>>8)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// addr0
		stReg.reg = 0x0244;
		u8RegData = (spiAddr)&0xFF;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// spi_req, PH
		stReg.reg = 0x0249;
		u8RegData = 0x80 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Period Check..
		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);

		// addr_rd_hold = 1, page = 0
		stReg.reg = 0x0258;
		u8RegData = 0x40 + fifoPageCnt;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// Fifo Addr = 0
		stReg.reg = 0x0259;
		u8RegData = 0x00;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// Data Dump.
		for(i = 0; i < remainSize; i++)
		{
			stReg.reg = 0x025A;
			if( (result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData)) < 0)
			{
				ErrorString("invalid read\n");
				return(result);
			}
			pData[i+(maxFifoPage*burstSize)] = u8RegData;
		}
		//** test_spi FIFO Read Done...   **
	}/*}}}*/
#if 0
	// Path_en + Edge Sel + Divider = 0
	stReg.reg = 0x0240;
	u8RegMask = 0x80;
	u8RegData = 0x00;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
#endif
	return(result);
}

int PR2000_OSG_EraseSPI(const int i2cFd, const uint8_t slvAddr, const uint32_t addr)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegMask;
	uint8_t u8RegData;
	uint32_t spiAddr = 0;
	int retryCnt = 0;

	Print("%02x-osg erase spi. addr:0x%08x\n", slvAddr COMMA addr);

	/* osg path disable */
	stReg.reg = 0x0280;
	u8RegMask = 0x80;
	u8RegData = 0x00;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// Path_en + Edge Sel + Divider = 1
	stReg.reg = 0x0240;
	u8RegMask = 0x80;
	u8RegData = 0x80;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	//** test_spi WREN start...   **
	// cmd = 06 for WREN (write)
	stReg.reg = 0x0241;
	u8RegData = 0x06;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// write + host_spi_data_size = 0 Ea
	stReg.reg = 0x0246;
	u8RegData = 0x00;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	stReg.reg = 0x0247;
	u8RegData = 0x00;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// cmd type = 1 cmd
	stReg.reg = 0x0248;
	u8RegData = 0x01;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// spi_req, page = 0
	stReg.reg = 0x0249;
	u8RegData = 0x80;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	retryCnt = 0;
	do
	{
		stReg.reg = 0x0249;
		u8RegData = 0;
		result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
		msleep(1);
		if(retryCnt++ > 100) return(-1);
		Dbg("u8RegData:0x%02x\n", u8RegData);
	} while(u8RegData & 0x80);
	//** test_spi WREN Done...   **

	//** Erase sector SPI Request Start...   **
	// cmd = 0x20:sector erase, 0xD8:block erase
	stReg.reg = 0x0241;
	u8RegData = 0x20;
	//u8RegData = 0xD8;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	spiAddr = addr;
	Dbg("Erase sector spiAddr:0x%08x\n", spiAddr);
	// addr2
	stReg.reg = 0x0242;
	u8RegData = (spiAddr>>16)&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	// addr1
	stReg.reg = 0x0243;
	u8RegData = (spiAddr>>8)&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	// addr0
	stReg.reg = 0x0244;
	u8RegData = (spiAddr)&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	// dummy cmd4
	stReg.reg = 0x0245;
	u8RegData = 0x00;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// write + host_spi_data_size = 64 Ea
	stReg.reg = 0x0246;
	u8RegData = 0x80;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	// burst_size
	stReg.reg = 0x0247;
	u8RegData = 0x00;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	// cmd type = 4 cmd
	stReg.reg = 0x0248;
	u8RegData = 0x04;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	// spi_req, PH
	stReg.reg = 0x0249;
	u8RegData = 0x80 + 0x00;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// SPI Write Period Check..
	retryCnt = 0;
	do
	{
		stReg.reg = 0x0249;
		u8RegData = 0;
		result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
		msleep(1);
		if(retryCnt++ > 100) return(-1);
		Dbg("u8RegData:0x%02x\n", u8RegData);
	} while(u8RegData & 0x80);

	// cmd = 05 for RDSR (Status Read)
	stReg.reg = 0x0241;
	u8RegData = 0x05;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	// single_rx[7] + host_spi_data_size = 1 Ea
	stReg.reg = 0x0246;
	u8RegData = 0x80;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	stReg.reg = 0x0247;
	u8RegData = 0x01;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	// rw_mode[7] + cmd type = 1 cmd + 1 read
	stReg.reg = 0x0248;
	u8RegData = 0x81;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	// SPI Write Status Check..
	do
	{
		// Status Read Request
		stReg.reg = 0x0249;
		u8RegData = 0x80;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		// SPI Write Period Check..
		retryCnt = 0;
		do
		{
			stReg.reg = 0x0249;
			u8RegData = 0;
			result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
			msleep(1);
			if(retryCnt++ > 100) return(-1);
			Dbg("u8RegData:0x%02x\n", u8RegData);
		} while(u8RegData & 0x80);

		// Status Data Check
		stReg.reg = 0x024A;
		u8RegData = 0;
		result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, (uint8_t *)&u8RegData);
	} while(u8RegData & 0x01);
#if 0
	// Path_en + Edge Sel + Divider = 0
	stReg.reg = 0x0240;
	u8RegMask = 0x80;
	u8RegData = 0x00;
	if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
#endif
	return(result);
}

int PR2000_OSG_SetLUTLoc(const int i2cFd, const uint8_t slvAddr, const uint32_t addr)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;
	uint32_t temp_addr;

	temp_addr = addr>>8;
	Print("%02x-osg lut addr:0x%08x\n", slvAddr COMMA temp_addr);
	/* mem loc */
	stReg.reg = 0x028C;
	u8RegData = (temp_addr>>8)&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	stReg.reg = 0x028D;
	u8RegData = (temp_addr)&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	return(result);
}

int PR2000_OSG_SetRLELoc(const int i2cFd, const uint8_t slvAddr, const uint32_t odd_addr, const uint32_t even_addr)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegData;
	uint32_t temp_addr;

	temp_addr = odd_addr>>8;	
	Dbg("%02x-0x88 osg rle odd  addr:0x%08lx\n", slvAddr COMMA temp_addr);
	/* mem loc */
	stReg.reg = 0x0288;
	u8RegData = (temp_addr>>8)&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	stReg.reg = 0x0289;
	u8RegData = (temp_addr)&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}

	
	temp_addr = even_addr>>8;
	Dbg("0x89 osg rle even addr:0x%08lx\n", temp_addr);
	/* mem loc */
	stReg.reg = 0x028A;
	u8RegData = (temp_addr>>8)&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	stReg.reg = 0x028B;
	u8RegData = (temp_addr)&0xFF;
	if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
	{
		ErrorString("invalid page write\n");
		return(result);
	}
	return(result);
}


int PR2000_OSG_Display(const int i2cFd, const uint8_t slvAddr, const int bEnable, const uint32_t addr)
{
	int result = -1;
	_stPR2000_Reg stReg;
	uint8_t u8RegMask;
	uint8_t u8RegData;

	Dbg("%02x-osg display en:%d, addr:0x%08lx\n", slvAddr COMMA bEnable COMMA addr*256);
	/* bEnable */
	if(bEnable)
	{
		
		/* osg display */ 
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, 1, 0x4F, 0x10)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}					
		
		// osg_path_en
		stReg.reg = 0x0280;
		u8RegMask = 0x80;
		u8RegData = 0x80;
		if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		// spi_Path_en
		stReg.reg = 0x0240;
		u8RegMask = 0x8F;
		u8RegData = 0x81;
		if( (result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		/* OSG_ODD_LOC */
		stReg.reg = 0x0288;
		u8RegData = (addr>>8)&0xFF;
		//printf("stReg.reg = [0x%02x] u8RegData= [0x%02x] || ",stReg.reg,u8RegData);
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		stReg.reg = 0x0289;
		u8RegData = (addr)&0xFF;
		//printf("stReg.reg = [0x%02x] u8RegData= [0x%02x] || ",stReg.reg,u8RegData);
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}		
		/* OSG_EVEN_LOC */
		stReg.reg = 0x028A;
		u8RegData = (addr>>8)&0xFF;
		//printf("stReg.reg = [0x%02x] u8RegData= [0x%02x] || ",stReg.reg,u8RegData);
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
		stReg.reg = 0x028B;
		u8RegData = (addr)&0xFF;
		//printf("stReg.reg = [0x%02x] u8RegData= [0x%02x] || ",stReg.reg,u8RegData);
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}	
		stReg.reg = 0x0293;
		u8RegData = 0x81;
		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}
	}



	return(result);
}

int PR2000_OSG_SetTable(const int i2cFd, const uint8_t slvAddr, const enum _eCameraStandard cameraStandard, const enum _eVideoResolution videoResolution)
{
	int result = -1;
	const _stPR2000_Table_STD_HDResolution *pTblSTDHDOSG = NULL;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	const _stPR2000_Table_EXT_HDResolution *pTblEXTHDOSG = NULL;
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	const _stPR2000_Table_SDResolution *pTblSDOSG = NULL;
	_stPR2000_Reg stReg;
	int regInx = 0;
	uint8_t u8RegData;

	Print("%02x-Set OSG Standard:%d, videoResolution:%d\n", slvAddr COMMA cameraStandard COMMA videoResolution);

	if(cameraStandard >= max_camera_standard)
	{
		Error("Invalid standard:%d\n", cameraStandard);
		return(result);
	}
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	if(videoResolution >= max_video_resolution)
	{
		Error("Invalid video resolution:%d\n", videoResolution);
		return(result);
	}
#else
	if(videoResolution > video_1920x1080p25)
	{
		Error("Invalid video resolution:%d\n", videoResolution);
		return(result);
	}
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	if(videoResolution > video_1920x1080p25)
	{/*{{{*/
		switch(cameraStandard)
		{
			case SD:
				{
					pTblSDOSG = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SD_OSGDisplay;
				}
				break;
			case PVI:
			case HDA:
			case CVI:
			case HDT_OLD:
			case HDT_NEW:
				{
					pTblEXTHDOSG = (const _stPR2000_Table_EXT_HDResolution *)stPR2000_Table_EXTHD_OSGDisplay;
				}
				break;
			default:
				{
					Error("Invalid camera Standard(%d)\n", cameraStandard);
					return(result);
				}
		}
	}/*}}}*/
	else
	{/*{{{*/
		switch(cameraStandard)
		{
			case SD:
				{
					pTblSDOSG = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SD_OSGDisplay;
				}
				break;
			case PVI:
			case HDA:
			case CVI:
			case HDT_OLD:
			case HDT_NEW:
				{
					pTblSTDHDOSG = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STDHD_OSGDisplay;
				}
				break;

			default:
				{
					Error("Invalid camera Standard(%d)\n", cameraStandard);
					return(result);
				}
		}
	}/*}}}*/
#else
	switch(cameraStandard)
	{/*{{{*/
		case SD:
			{
				pTblSDOSG = (const _stPR2000_Table_SDResolution *)stPR2000_Table_SD_OSGDisplay;
			}
			break;
		case PVI:
		case HDA:
		case CVI:
		case HDT_OLD:
		case HDT_NEW:
			{
				pTblSTDHDOSG = (const _stPR2000_Table_STD_HDResolution *)stPR2000_Table_STDHD_OSGDisplay;
			}
			break;
		default:
			{
				Error("Invalid camera Standard(%d)\n", cameraStandard);
				return(result);
			}
	}/*}}}*/
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 

	if( (cameraStandard == SD) && (pTblSDOSG != NULL) )
	{
		regInx = 0;
		stReg.reg = pTblSDOSG[regInx].stReg.reg;
		while(stReg.reg != 0xFFFF)
		{
			u8RegData = pTblSDOSG[regInx].u8Data[videoResolution];
			Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

			if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
			{
				ErrorString("invalid page write\n");
				return(result);
			}

			regInx++;
			stReg.reg = pTblSDOSG[regInx].stReg.reg;
		}
	}
	else
	{
		if( (pTblSTDHDOSG != NULL) )
		{/*{{{*/
			regInx = 0;
			stReg.reg = pTblSTDHDOSG[regInx].stReg.reg;
			while(stReg.reg != 0xFFFF)
			{
				u8RegData = pTblSTDHDOSG[regInx].u8Data[videoResolution-video_1280x720p60]; 
				Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}

				regInx++;
				stReg.reg = pTblSTDHDOSG[regInx].stReg.reg;
			}
		}/*}}}*/
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
		if( (pTblEXTHDOSG != NULL) )
		{/*{{{*/
			regInx = 0;
			stReg.reg = pTblEXTHDOSG[regInx].stReg.reg;
			while(stReg.reg != 0xFFFF)
			{
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
				u8RegData = pTblEXTHDOSG[regInx].u8Data[videoResolution-video_1280x800p60]; 
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
				u8RegData = pTblEXTHDOSG[regInx].u8Data[videoResolution-video_1280x960p60]; 
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) 
				Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

				if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
				{
					ErrorString("invalid page write\n");
					return(result);
				}

				regInx++;
				stReg.reg = pTblEXTHDOSG[regInx].stReg.reg;
			}
		}/*}}}*/
#endif //defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION) 
	}

	return(result);

}
#endif // SUPPORT_OSG

#ifdef SUPPORT_REG_SAVEDUMP //support pr2000 register save dump.
void PR2000_PRINT_MKTBL(const int i2cFd, const uint8_t slvAddr)
{/*{{{*/
	unsigned char page;
	_stAttrChip *pstPr2000AttrChip;
	int chipInx = 0;
	int find = 0;
	_stPR2000_Reg stReg;
	uint8_t u8Data; 
	int i;

	const _stPR2000_Table_Common stPR2000_Table_PrevReset[2] =  {
		{ {0x00A1}, 0xFF},
		{ {0x00FF}, 0x80},
	};

	const _stPR2000_Table_Common stPR2000_Table_PostApply[2] =  {
		{ {0x0154}, 0x0E},
		{ {0x0154}, 0x0F},
	};

	/* copy from "PR2000_SetTableMipiParallel()" */
	const _stPR2000_Table_Common stPR2000_Table_StartMipi_4Lane[] = 
	{/*{{{*/
		/* page+reg, data */
		// MIPI Start Sequence
		{ {0x0040}, 0x00},           // dphy Start
		{ {0x004E}, 0x40},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 00h. 4lane
		{ {0x0040}, 0x40},           //enable mipi
		// 1usec dely
		{ {0x004E}, 0x60},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 20h : DLL_PD Toggle. 4lane
		// 1usec dely
		{ {0x004E}, 0x40},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 00h. 4lane
		// 1usec dely
		{ {0x0047}, 0xBA},       //mipi_en & Frame Mode. 4lane

		/* End */
		{  {0xFFFF}, 0xFF} //end
	};/*}}}*/

	/* copy from "PR2000_SetTableMipiParallel()" */
	const _stPR2000_Table_Common stPR2000_Table_StartMipi_2Lane[] = 
	{/*{{{*/
		/* page+reg, data */
		// MIPI Start Sequence
		{ {0x0040}, 0x00},           // dphy Start
		{ {0x004E}, 0x4C},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 00h. 2lane
		{ {0x0040}, 0x40},           //enable mipi
		// 1usec dely
		{ {0x004E}, 0x6C},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 20h : DLL_PD Toggle. 2lane
		// 1usec dely
		{ {0x004E}, 0x4C},           // dphy_vctrl_init=0, dphy_fld = 1, dphy_pd = 00h. 2lane
		// 1usec dely
		{ {0x0047}, 0x9A},       //mipi_en & Frame Mode. 2lane

		/* End */
		{  {0xFFFF}, 0xFF} //end
	};/*}}}*/


	/* get chip attribute */
	for(chipInx = 0; chipInx < MAX_PR2000_CHIPCNT; chipInx++)
	{
		if(PR2000_ATTR_CHIP[chipInx].i2cSlvAddr == slvAddr)
		{
			find = 1;
			break;
		}
	}
	if(!find) return;

	pstPr2000AttrChip = &PR2000_ATTR_CHIP[chipInx];

	PRINTF("mktbl: \n");

	Dbg("i2cSlv:0x%02x\n", slvAddr);
	if(gpRegSaveDump[chipInx])
	{
		if(gpRegSaveDump[chipInx]->i2cSlvAddr == slvAddr)
		{
			Dbg("find i2cSlv:0x%02x, chipInx:%d-0x%02x\n", slvAddr COMMA chipInx COMMA gpRegSaveDump[chipInx]->i2cSlvAddr);

			PRINTF("\n\nPR2000 Driver Set Tbl [%s]\n", _VER_PR2000);
			PRINTF("//Camera:%d(%s), cameraResolution:%d(%s), videoResolution:%d(%s), %s\n", gpDrvHost[chipInx]->stPrRxMode.standard COMMA _strCameraStandard[gpDrvHost[chipInx]->stPrRxMode.standard] COMMA gpDrvHost[chipInx]->stPrRxMode.cameraResolution COMMA _strCameraResolution[gpDrvHost[chipInx]->stPrRxMode.cameraResolution] COMMA gpDrvHost[chipInx]->stPrRxMode.vidOutResolution COMMA _strVideoResolution[gpDrvHost[chipInx]->stPrRxMode.vidOutResolution] COMMA (PR2000_ATTR_CHIP[chipInx].vidOutMode!=0)?"MIPI":"Parallel");
			PRINTF("   [CHIP%d]:I2C SlvAddr(0x%02X)\n", chipInx, PR2000_ATTR_CHIP[chipInx].i2cSlvAddr>>1);

			PRINTF("    vinMode(0:[Differential|VinPN], 1:VinP, 3:VinN): %d\n", PR2000_ATTR_CHIP[chipInx].vinMode);
			PRINTF("    vidOutMode(0:pararllel, 2:mipi_2lane(~HD), 4:mipi_4lane(~FHD): %d\n", PR2000_ATTR_CHIP[chipInx].vidOutMode);
			PRINTF("    cascade(0:no, 1:cascade): %d\n", PR2000_ATTR_CHIP[chipInx].bCascade);
			PRINTF("    cascadeMux(If cascade, 0:single(slave), 1:mux(master)): %d\n", PR2000_ATTR_CHIP[chipInx].bCascadeMux);
			PRINTF("    chid_num(If cascade, 0:master, 1:slave): %d\n", PR2000_ATTR_CHIP[chipInx].chid_num);
			PRINTF("    bt656(If parallel, 0:bt1120(8bit), 1:bt656(8bit)): %d\n", PR2000_ATTR_CHIP[chipInx].bBt656);
			PRINTF("    datarate(If parallel, 0:148.5Mhz, 1:74.25Mhz, 2:36Mhz, 3:27Mhz): %d\n", PR2000_ATTR_CHIP[chipInx].datarate);
			PRINTF("    clkphase_Mux(If parallel & cascadeMux, clkphase:0~15): %d\n", PR2000_ATTR_CHIP[chipInx].clkphase_Mux);
			PRINTF("    clkphase_148Mhz(If parallel & datarate=0, clkphase:0~15): %d\n", PR2000_ATTR_CHIP[chipInx].clkphase_148Mhz);
			PRINTF("    clkphase_74Mhz(If parallel & datarate=1, clkphase:0~15): %d\n", PR2000_ATTR_CHIP[chipInx].clkphase_74Mhz);
			PRINTF("    clkphase_36Mhz(If parallel & datarate=2, clkphase:0~3): %d\n", PR2000_ATTR_CHIP[chipInx].clkphase_36Mhz);
			PRINTF("    clkphase_27Mhz(If parallel & datarate=3, clkphase:0~3): %d\n", PR2000_ATTR_CHIP[chipInx].clkphase_27Mhz);

			#if 0 //print "slv, page, addr, data"
			//Print Prev Reset
			{/*{{{*/
				PRINTF("///////////////////////////////////////////////\n");
				PRINTF("/// slv, page, addr, data/////////////////////\n");
				PRINTF("  > 0x%02x, %d, 0x%02x, 0x%02x]\n", 0x5C<<1, stPR2000_Table_PrevReset[0].stReg.b.page, stPR2000_Table_PrevReset[0].stReg.b.addr,  stPR2000_Table_PrevReset[0].u8Data);
				PRINTF("  > 0x%02x, %d, 0x%02x, 0x%02x]\n", 0x5D<<1, stPR2000_Table_PrevReset[0].stReg.b.page, stPR2000_Table_PrevReset[0].stReg.b.addr,  stPR2000_Table_PrevReset[0].u8Data);
				PRINTF("  > 0x%02x, %d, 0x%02x, 0x%02x]\n", 0x5E<<1, stPR2000_Table_PrevReset[0].stReg.b.page, stPR2000_Table_PrevReset[0].stReg.b.addr,  stPR2000_Table_PrevReset[0].u8Data);
				PRINTF("  > 0x%02x, %d, 0x%02x, 0x%02x]\n", 0x5F<<1, stPR2000_Table_PrevReset[0].stReg.b.page, stPR2000_Table_PrevReset[0].stReg.b.addr,  stPR2000_Table_PrevReset[0].u8Data);
				PRINTF("  > 0x%02x, %d, 0x%02x, 0x%02x]\n", 0x5C<<1, stPR2000_Table_PrevReset[1].stReg.b.page, stPR2000_Table_PrevReset[1].stReg.b.addr,  stPR2000_Table_PrevReset[1].u8Data);
				PRINTF("  > 0x%02x, %d, 0x%02x, 0x%02x]\n", 0x5D<<1, stPR2000_Table_PrevReset[1].stReg.b.page, stPR2000_Table_PrevReset[1].stReg.b.addr,  stPR2000_Table_PrevReset[1].u8Data);
				PRINTF("  > 0x%02x, %d, 0x%02x, 0x%02x]\n", 0x5E<<1, stPR2000_Table_PrevReset[1].stReg.b.page, stPR2000_Table_PrevReset[1].stReg.b.addr,  stPR2000_Table_PrevReset[1].u8Data);
				PRINTF("  > 0x%02x, %d, 0x%02x, 0x%02x]\n", 0x5F<<1, stPR2000_Table_PrevReset[1].stReg.b.page, stPR2000_Table_PrevReset[1].stReg.b.addr,  stPR2000_Table_PrevReset[1].u8Data);
			}/*}}}*/

			//Print page
			//for(page = 0; page < 3; page++) //all register
			for(page = 0; page < 2; page++) //page0, page1
			{/*{{{*/
				for(i = 0; i < 0xFF; i++)
				{
					if(i == 0)
					{
						if(page == 0) {      PRINTF("\n//                      Page0 sys\n"); }
						else if(page == 1) { PRINTF("\n//                      Page1 vdec\n"); }
						else if(page == 2) { PRINTF("\n//                      Page2 utc\n"); }
					}
					else if( (i == 0x80) && (page == 2) )
					{ 
						PRINTF("\n//                      Page2 osg\n");
					}
					if(gpRegSaveDump[chipInx]->regTbl[page][i].stReg.reg != 0xFFFF)
					{
						if( (page == 0) && (gpRegSaveDump[chipInx]->regTbl[page][i].stReg.reg == 0x0011) )
						{
							gpRegSaveDump[chipInx]->regTbl[page][i].u8Data = 0x07; //forcely manual setting.
						}
						PRINTF("  > 0xb8, %d, 0x%02x, 0x%02x]\n", gpRegSaveDump[chipInx]->regTbl[page][i].stReg.b.page, gpRegSaveDump[chipInx]->regTbl[page][i].stReg.b.addr,  gpRegSaveDump[chipInx]->regTbl[page][i].u8Data);
					}
				}
			}/*}}}*/

			//Print Post apply 
			{/*{{{*/
				PRINTF("\n");
				PRINTF("  > 0xb8, %d, 0x%02x, 0x%02x]\n", stPR2000_Table_PostApply[0].stReg.b.page, stPR2000_Table_PostApply[0].stReg.b.addr,  stPR2000_Table_PostApply[0].u8Data);
				PRINTF("  > 0xb8, %d, 0x%02x, 0x%02x]\n", stPR2000_Table_PostApply[1].stReg.b.page, stPR2000_Table_PostApply[1].stReg.b.addr,  stPR2000_Table_PostApply[1].u8Data);
				PRINTF("\n");

				if( PR2000_ATTR_CHIP[chipInx].vidOutMode == 2) //mipi 2lane
				{
					PRINTF("\n//                      mipi 2lane\n");
					i = 0;
					stReg.reg = stPR2000_Table_StartMipi_2Lane[i].stReg.reg;
					u8Data = stPR2000_Table_StartMipi_2Lane[i].u8Data;
					while(stReg.reg != 0xFFFF)
					{
						PRINTF("  > 0xb8, %d, 0x%02x, 0x%02x]\n", stReg.b.page, stReg.b.addr, u8Data);
						i++;
						stReg.reg = stPR2000_Table_StartMipi_2Lane[i].stReg.reg;
						u8Data = stPR2000_Table_StartMipi_2Lane[i].u8Data;
					}
				}
				else if( PR2000_ATTR_CHIP[chipInx].vidOutMode == 4) //mipi 4lane
				{
					PRINTF("\n//                      mipi 4lane\n");
					i = 0;
					stReg.reg = stPR2000_Table_StartMipi_4Lane[i].stReg.reg;
					u8Data = stPR2000_Table_StartMipi_4Lane[i].u8Data;
					while(stReg.reg != 0xFFFF)
					{
						PRINTF("  > 0xb8, %d, 0x%02x, 0x%02x]\n", stReg.b.page, stReg.b.addr, u8Data);
						i++;
						stReg.reg = stPR2000_Table_StartMipi_4Lane[i].stReg.reg;
						u8Data = stPR2000_Table_StartMipi_4Lane[i].u8Data;
					}
				}
				else //parallel
				{
					uint8_t (*ppTbl)[3];
					uint8_t *pTbl;
					PRINTF("\n//////////////////////// clkphase control register. //////////\n");
					PRINTF("\n//If noise, control below register and choise center value of normal phases.//\n");
					PRINTF("    datarate(If parallel, 0:148.5Mhz, 1:74.25Mhz, 2:36Mhz, 3:27Mhz): %d\n", PR2000_ATTR_CHIP[chipInx].datarate);
					if(PR2000_ATTR_CHIP[chipInx].datarate == 0)
					{
						ppTbl = (uint8_t (*)[3])pr2000_table_148Mhzclk_phase;
					}
					else if(PR2000_ATTR_CHIP[chipInx].datarate == 1)
					{
						ppTbl = (uint8_t (*)[3])pr2000_table_74Mhzclk_phase;
					}
					else if(PR2000_ATTR_CHIP[chipInx].datarate == 2)
					{
						pTbl = (uint8_t *)pr2000_table_36Mhzclk_phase;
					}
					else
					{
						pTbl = (uint8_t *)pr2000_table_27Mhzclk_phase;
					}

					if( PR2000_ATTR_CHIP[chipInx].datarate <= 1 )
					{
						PRINTF("  /*0x00E3&00E4(3F),0x00E2(30),0x00D8(07) ()->maskbit */\n");
						for(i = 0; i < 16; i++)
						{
							PRINTF("       0x%02x,          0x%02x,      0x%02x //phase %d \n", ppTbl[i][0], ppTbl[i][1], ppTbl[i][2], i);
						}
					}
					else
					{
						PRINTF("  /*0x00E3&00E4(3F) ()->maskbit */\n");
						for(i = 0; i < 4; i++)
						{
							PRINTF("       0x%02x //phase %d \n", pTbl[i], i);
						}

					}
				}

				PRINTF("///////////////////////////////////////////////\n");
			}/*}}}*/

			#else //print "slv, addr, data"

			//Print Prev Reset
			{/*{{{*/
				PRINTF("///////////////////////////////////////////////\n");
				PRINTF("/// slv, addr, data/////////////////////\n");
				PRINTF("  > 0x%02x, 0xff, 0x00]\n", 0x5C<<1);
				PRINTF("  > 0x%02x, 0x%02x, 0x%02x]\n", 0x5C<<1, stPR2000_Table_PrevReset[0].stReg.b.addr,  stPR2000_Table_PrevReset[0].u8Data);
				PRINTF("  > 0x%02x, 0xff, 0x00]\n", 0x5D<<1);
				PRINTF("  > 0x%02x, 0x%02x, 0x%02x]\n", 0x5D<<1, stPR2000_Table_PrevReset[0].stReg.b.addr,  stPR2000_Table_PrevReset[0].u8Data);
				PRINTF("  > 0x%02x, 0xff, 0x00]\n", 0x5E<<1);
				PRINTF("  > 0x%02x, 0x%02x, 0x%02x]\n", 0x5E<<1, stPR2000_Table_PrevReset[0].stReg.b.addr,  stPR2000_Table_PrevReset[0].u8Data);
				PRINTF("  > 0x%02x, 0xff, 0x00]\n", 0x5F<<1);

				PRINTF("  > 0x%02x, 0x%02x, 0x%02x]\n", 0x5F<<1, stPR2000_Table_PrevReset[0].stReg.b.addr,  stPR2000_Table_PrevReset[0].u8Data);
				PRINTF("  > 0x%02x, 0x%02x, 0x%02x]\n", 0x5C<<1, stPR2000_Table_PrevReset[1].stReg.b.addr,  stPR2000_Table_PrevReset[1].u8Data);
				PRINTF("  > 0x%02x, 0x%02x, 0x%02x]\n", 0x5D<<1, stPR2000_Table_PrevReset[1].stReg.b.addr,  stPR2000_Table_PrevReset[1].u8Data);
				PRINTF("  > 0x%02x, 0x%02x, 0x%02x]\n", 0x5E<<1, stPR2000_Table_PrevReset[1].stReg.b.addr,  stPR2000_Table_PrevReset[1].u8Data);
				PRINTF("  > 0x%02x, 0x%02x, 0x%02x]\n", 0x5F<<1, stPR2000_Table_PrevReset[1].stReg.b.addr,  stPR2000_Table_PrevReset[1].u8Data);
			}/*}}}*/

			//Print page
			//for(page = 0; page < 3; page++) //all register
			for(page = 0; page < 2; page++) //page0, page1
			{/*{{{*/
				for(i = 0; i < 0xFF; i++)
				{
					if(i == 0)
					{
						if(page == 0) 
						{      
							PRINTF("\n//                      Page0 sys\n");
							PRINTF("  > 0xb8, 0xff, 0x00]\n");
						}
						else if(page == 1) 
						{ 
							PRINTF("\n//                      Page1 vdec\n"); 
							PRINTF("  > 0xb8, 0xff, 0x01]\n");
						}
						else if(page == 2) 
						{ 
							PRINTF("\n//                      Page2 utc\n"); 
							PRINTF("  > 0xb8, 0xff, 0x02]\n");
						}
					}
					else if( (i == 0x80) && (page == 2) )
					{ 
						PRINTF("\n//                      Page2 osg\n");
						PRINTF("  > 0xb8, 0xff, 0x02]\n");
					}
					if(gpRegSaveDump[chipInx]->regTbl[page][i].stReg.reg != 0xFFFF)
					{
						if( (page == 0) && (gpRegSaveDump[chipInx]->regTbl[page][i].stReg.reg == 0x0011) )
						{
							gpRegSaveDump[chipInx]->regTbl[page][i].u8Data = 0x07; //forcely manual setting.
						}
						PRINTF("  > 0xb8, 0x%02x, 0x%02x]\n", gpRegSaveDump[chipInx]->regTbl[page][i].stReg.b.addr,  gpRegSaveDump[chipInx]->regTbl[page][i].u8Data);
					}
				}
			}/*}}}*/

			//Print Post apply 
			{/*{{{*/
				PRINTF("\n");
				PRINTF("  > 0xb8, 0xff, 0x%02x]\n", stPR2000_Table_PostApply[0].stReg.b.page);
				PRINTF("  > 0xb8, 0x%02x, 0x%02x]\n", stPR2000_Table_PostApply[0].stReg.b.addr,  stPR2000_Table_PostApply[0].u8Data);
				PRINTF("  > 0xb8, 0xff, 0x%02x]\n", stPR2000_Table_PostApply[1].stReg.b.page);
				PRINTF("  > 0xb8, 0x%02x, 0x%02x]\n", stPR2000_Table_PostApply[1].stReg.b.addr,  stPR2000_Table_PostApply[1].u8Data);
				PRINTF("\n");

				if( PR2000_ATTR_CHIP[chipInx].vidOutMode == 2) //mipi 2lane
				{
					PRINTF("\n//                      mipi 2lane\n");
					i = 0;
					stReg.reg = stPR2000_Table_StartMipi_2Lane[i].stReg.reg;
					u8Data = stPR2000_Table_StartMipi_2Lane[i].u8Data;
					while(stReg.reg != 0xFFFF)
					{
						PRINTF("  > 0xb8, 0xff, 0x%02x]\n", stReg.b.page);
						PRINTF("  > 0xb8, 0x%02x, 0x%02x]\n", stReg.b.addr, u8Data);
						i++;
						stReg.reg = stPR2000_Table_StartMipi_2Lane[i].stReg.reg;
						u8Data = stPR2000_Table_StartMipi_2Lane[i].u8Data;
					}
				}
				else if( PR2000_ATTR_CHIP[chipInx].vidOutMode == 4) //mipi 4lane
				{
					PRINTF("\n//                      mipi 4lane\n");
					i = 0;
					stReg.reg = stPR2000_Table_StartMipi_4Lane[i].stReg.reg;
					u8Data = stPR2000_Table_StartMipi_4Lane[i].u8Data;
					while(stReg.reg != 0xFFFF)
					{
						PRINTF("  > 0xb8, 0xff, 0x%02x]\n", stReg.b.page);
						PRINTF("  > 0xb8, 0x%02x, 0x%02x]\n", stReg.b.addr, u8Data);
						i++;
						stReg.reg = stPR2000_Table_StartMipi_4Lane[i].stReg.reg;
						u8Data = stPR2000_Table_StartMipi_4Lane[i].u8Data;
					}
				}
				else //parallel
				{
					uint8_t (*ppTbl)[3];
					uint8_t *pTbl;
					PRINTF("\n//////////////////////// clkphase control register. //////////\n");
					PRINTF("\n//If noise, control below register and choise center value of normal phases.//\n");
					PRINTF("    datarate(If parallel, 0:148.5Mhz, 1:74.25Mhz, 2:36Mhz, 3:27Mhz): %d\n", PR2000_ATTR_CHIP[chipInx].datarate);
					if(PR2000_ATTR_CHIP[chipInx].datarate == 0)
					{
						ppTbl = (uint8_t (*)[3])pr2000_table_148Mhzclk_phase;
					}
					else if(PR2000_ATTR_CHIP[chipInx].datarate == 1)
					{
						ppTbl = (uint8_t (*)[3])pr2000_table_74Mhzclk_phase;
					}
					else if(PR2000_ATTR_CHIP[chipInx].datarate == 2)
					{
						pTbl = (uint8_t *)pr2000_table_36Mhzclk_phase;
					}
					else
					{
						pTbl = (uint8_t *)pr2000_table_27Mhzclk_phase;
					}

					if( PR2000_ATTR_CHIP[chipInx].datarate <= 1 )
					{
						PRINTF("  /*0x00E3&00E4(3F),0x00E2(30),0x00D8(07) ()->maskbit */\n");
						for(i = 0; i < 16; i++)
						{
							PRINTF("       0x%02x,          0x%02x,      0x%02x //phase %d \n", ppTbl[i][0], ppTbl[i][1], ppTbl[i][2], i);
						}
					}
					else
					{
						PRINTF("  /*0x00E3&00E4(3F) ()->maskbit */\n");
						for(i = 0; i < 4; i++)
						{
							PRINTF("       0x%02x //phase %d \n", pTbl[i], i);
						}

					}
				}

				PRINTF("///////////////////////////////////////////////\n");
			}/*}}}*/

			#endif
		}
	}

	return;

}/*}}}*/
#endif // SUPPORT_REG_SAVEDUMP //support pr2000 register save dump.


#ifdef SUPPORT_FPGA

int PR2000_FPGA_SetTable(const int i2cFd, const uint8_t slvAddr)
{
	int result = -1;
	const _stPR2000_Table_Common *pTblFPGA = NULL;
	_stPR2000_Reg stReg;
	int regInx = 0;
	uint8_t u8RegData;

	const _stPR2000_Table_Common stPR2000_Table_FPGA[] = 
	{/*{{{*/
		/* page+reg, data */
		/* 0Page */
		{  {0x0014}, 0x21},	
		//{  {0x0014}, 0xA1},	
		{  {0x00A0}, 0x01},
		{  {0x00A1}, 0xFF},
		{  {0x00A2}, 0x00},
		{  {0x00A3}, 0x00},
		{  {0x00A4}, 0x11},
		{  {0x00A5}, 0xE3},
		{  {0x00A6}, 0x00},
		{  {0x00A7}, 0x80},
		{  {0x00A8}, 0x08},

		{  {0x00D0}, 0x00},
		{  {0x00D1}, 0x00},
		//{  {0x00D2}, 0x21},
		{  {0x00D2}, 0x0A},
		{  {0x00D3}, 0x00},

		{  {0x00D8}, 0x00},
		{  {0x00D9}, 0x00},
		//{  {0x00DA}, 0x21},
		{  {0x00DA}, 0x02},

		{  {0x0044}, 0x00},

		/* mipi */
		{  {0x00E8}, 0x00},
		{  {0x00E9}, 0x00},
		{  {0x00EA}, 0x03},
		{  {0x00EB}, 0xFF},

		{  {0x0045}, 0x06},
		{  {0x0046}, 0x04},

		/* End */
		{  {0xFFFF}, 0xFF}, //end
	};/*}}}*/

	PrintString("Set fpga register\n");

	pTblFPGA = (const _stPR2000_Table_Common *)stPR2000_Table_FPGA;
	regInx = 0;
	stReg.reg = pTblFPGA[regInx].stReg.reg;
	while(stReg.reg != 0xFFFF)
	{
		u8RegData = pTblFPGA[regInx].u8Data;
		Dbg("inx:%d, page:%d, reg:0x%02x, data:0x%02x\n", regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);

		if( (result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
		{
			ErrorString("invalid page write\n");
			return(result);
		}

		regInx++;
		stReg.reg = pTblFPGA[regInx].stReg.reg;
	}

	return(result);
}

#if defined(__HOST_MICOM_SYSTEM__)
#if 0
void PR2000_FPGA_SetSADDR(uint8_t saddr)
{
	Print("Set saddr:0x%02x\n", saddr);
	switch(saddr)
	{
		case 0x00:
		{
			GPIO_ResetBits(GPIOC, GPIO_Pin_15); //saddr[1]:gpioC15
			GPIO_ResetBits(GPIOB, GPIO_Pin_1); //saddr[0]:gpioB1
		}
		break;
		case 0x01:
		{
			GPIO_ResetBits(GPIOC, GPIO_Pin_15); //saddr[1]:gpioC15
			GPIO_SetBits(GPIOB, GPIO_Pin_1); //saddr[0]:gpioB1
		}
		break;
		case 0x02:
		{
			GPIO_SetBits(GPIOC, GPIO_Pin_15); //saddr[1]:gpioC15
			GPIO_ResetBits(GPIOB, GPIO_Pin_1); //saddr[0]:gpioB1
		}
		break;
		case 0x03:
		{
			GPIO_SetBits(GPIOC, GPIO_Pin_15); //saddr[1]:gpioC15
			GPIO_SetBits(GPIOB, GPIO_Pin_1); //saddr[0]:gpioB1
		}
		break;
		default:
		{
			ErrorString("Invalid saddr\n");
		}
		break;
	}
}
#endif
#endif //defined(__HOST_MICOM_SYSTEM__)
#endif // SUPPORT_FPGA

#ifdef SUPPORT_CPLD
int PR2000_CPLD_SetTable(const uint8_t vidOutMode, const uint8_t dataRate)
{
	int result = -1;

        uint8_t u8I2cSlv = 0;
        uint8_t u8I2cReg = 0;
        uint8_t u8I2cData = 0;

	PrintString("Set cpld register\n");

	u8I2cSlv = 0x51;
	u8I2cReg = 0x20;
	u8I2cData = 0x00;
	if( (result = PR2000_Read(0, u8I2cSlv<<1, u8I2cReg, &u8I2cData)) < 0)
	{
		ErrorString("invalid read\n");
		return(result);
	}
	Print("Read: slv:0x%02x, reg:0x%02x, data:0x%02x\n", u8I2cSlv COMMA u8I2cReg COMMA u8I2cData);

	/* 0x80: Parallel_B(cascade) */
	/* 0x10: Mipi_A */
	/* 0x00: Parallel_A */
	if(u8I2cData == 0x00)
	{
		PrintString("Parallel_A\n");
	}
	else if(u8I2cData == 0x10)
	{
		PrintString("Mipi_A\n");
		u8I2cSlv = 0x51;
		u8I2cReg = 0x10;
		u8I2cData = 0x08;
		Print("slv:0x%02x, reg:0x%02x, data:0x%02x\n", u8I2cSlv COMMA u8I2cReg COMMA u8I2cData);
		if( (result = PR2000_Write(0, u8I2cSlv<<1, u8I2cReg, u8I2cData)) < 0)
		{
			ErrorString("invalid write\n");
			return(result);
		}
	}
	else if(u8I2cData == 0x80)
	{
		PrintString("Parallel_B(Cascade)\n");
		u8I2cSlv = 0x51;
		u8I2cReg = 0x10;
		u8I2cData = 0x00;
		Print("slv:0x%02x, reg:0x%02x, data:0x%02x\n", u8I2cSlv COMMA u8I2cReg COMMA u8I2cData);
		if( (result = PR2000_Write(0, u8I2cSlv<<1, u8I2cReg, u8I2cData)) < 0)
		{
			ErrorString("invalid write\n");
			return(result);
		}
	}
	else
	{
		ErrorString("Invalid CPLD ID\n");
		return(-1);
	}

	return(result);
}
#endif // SUPPORT_CPLD



